https://github.com/robb-randall/owmo
Ruby openweathermap.org API
https://github.com/robb-randall/owmo
openweathermap openweathermap-api ruby ruby-gem rubygems
Last synced: 3 months ago
JSON representation
Ruby openweathermap.org API
- Host: GitHub
- URL: https://github.com/robb-randall/owmo
- Owner: robb-randall
- License: mit
- Created: 2017-06-05T01:01:12.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2023-01-16T20:19:29.000Z (over 3 years ago)
- Last Synced: 2025-12-04T15:13:31.928Z (6 months ago)
- Topics: openweathermap, openweathermap-api, ruby, ruby-gem, rubygems
- Language: Ruby
- Homepage:
- Size: 79.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.MD
- License: LICENSE.txt
Awesome Lists containing this project
README
# OWMO - OpenWeatherMap.Org Client API
Ruby client for openweathermap.org client API. Currently only for current and forecast information.
[](https://badge.fury.io/rb/owmo)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'owmo'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install owmo
## Usage
You'll need and API key from [OpenWeatherMap.org](http://openweathermap.org/appid).
Complete examples can be found under owmo/examples.
----
### Quick Start
```ruby
require 'owmo'
api_key = ""
puts OWMO::weather(api_key).get :current, city_name: "London,UK"
```
```ruby
require 'owmo'
api_key = ""
weather = OWMO::weather api_key
puts weather.get :current, city_name: "London,UK"
```
```ruby
require 'owmo'
api_key = ""
OWMO::weather(api_key) { |weather| puts weather.get :current, city_name: "London,UK" }
```
----
### Weather Information
#### [Current weather data](http://openweathermap.org/current)
```ruby
OWMO::weather(api_key).get :current, city_name: "London,UK"
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/current.rb)
### [Current weather data for multiple cities](http://openweathermap.org/current#severalid)
```ruby
OWMO::weather(api_key).get :group, city_id: [4850751,4887398,2643743,4164138,5368361].join(",")
```
#### [5 day weather forecast](http://openweathermap.org/forecast5)
```ruby
OWMO::weather(api_key).get :forecast5, city_name: "London,UK"
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast5.rb)
#### [16 day weather forecast](http://openweathermap.org/forecast16)
```ruby
OWMO::weather(api_key).get :forecast16, city_name: "London,UK"
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast16.rb)
----
### Query parameters
#### Geocode (required)
```ruby
# Geocode by City ID
OWMO::weather(api_key).get :current, city_id: 5328041
OWMO::weather(api_key).get :current, id: 5328041
# Geocode by City Name
OWMO::weather(api_key).get :current, city_name: "Beverly Hills"
OWMO::weather(api_key).get :current, q: "Beverly Hills"
# Geocode by Zip Code
OWMO::weather(api_key).get :current, zip: 90210
OWMO::weather(api_key).get :current, zip_code: 90210
# Geocode by Coordinance
OWMO::weather(api_key).get :current, lon: -118.41, lat: 34.09
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_geocode.rb)
#### Mode
```ruby
# Response in JSON format (default)
OWMO::weather(api_key).get :current, city_name: "London,UK"
OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :json
# Response in XML format
OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :xml
# Response in HTML format
OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :html
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_mode.rb)
#### Units
```ruby
# Kelvin (default)
OWMO::weather(api_key).get :current, city_name: "London,UK"
# Imperial
OWMO::weather(api_key).get :current, city_name: "London,UK", units: :imperial
# Metric
OWMO::weather(api_key).get :current, city_name: "London,UK", units: :metric
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_units.rb)
#### All
```ruby
query = {
city_name: "London,UK",
mode: 'json',
units: 'imperial',
lang: 'fr'
}
OWMO::weather(api_key).get :current, query
```
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_all.rb)
----
### Working example using Sinatra
```ruby
require 'owmo'
require 'sinatra' # Need to install, not included in gemspec
require 'uri'
get '/current/:name' do
api_key = ''
weather = OWMO::Weather.new api_key
weather.get :current, city_name: params[:name], mode: :html
end
```
Then navigate to: http://localhost:4567/current/London,UK
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/sinatra_example.rb)
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).