OWMO - OpenWeatherMap.Org Client API

Ruby client for openweathermap.org client API. Currently only for current and forecast information.

Gem Version

Installation

Add this line to your application's Gemfile:

gem 'owmo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install owmo

Usage

You'll need and API key from OpenWeatherMap.org.

Complete examples can be found under owmo/examples.


Quick Start

require 'owmo'
api_key = "<api key here>"
puts OWMO::weather(api_key).get :current, city_name: "London,UK"
require 'owmo'
api_key = "<api key here>"
weather = OWMO::weather api_key
puts weather.get :current, city_name: "London,UK"
require 'owmo'
api_key = "<api key here>"
OWMO::weather(api_key) { |weather| puts weather.get :current, city_name: "London,UK" }

Weather Information

Current weather data

OWMO::weather(api_key).get :current, city_name: "London,UK"

Full example

Current weather data for multiple cities

OWMO::weather(api_key).get :group, city_id: [4850751,4887398,2643743,4164138,5368361].join(",")

5 day weather forecast

OWMO::weather(api_key).get :forecast5, city_name: "London,UK"

Full example

16 day weather forecast

OWMO::weather(api_key).get :forecast16, city_name: "London,UK"

Full example


Query parameters

Geocode (required)

# 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

Mode

# 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

Units

# 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

All

query = {
  city_name: "London,UK",
  mode: 'json',
  units: 'imperial',
  lang: 'fr'
}

OWMO::weather(api_key).get :current, query

Full example


Working example using Sinatra

require 'owmo'
require 'sinatra' # Need to install, not included in gemspec
require 'uri'

get '/current/:name' do
    api_key = '<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

License

The gem is available as open source under the terms of the MIT License.