OpenWeatherApi wrapper for Ruby
Simple wrapper for Open Weather Map API.
Please visit the this link for more information.
Installation
Add this line to your application's Gemfile:
gem 'open-weather-api'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install open-weather-api
Usage
First, you need to init the API:
Rails
# config/initializers/open-weather-api.rb
Rails.configuration.open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'], language: 'es', units: 'metric'
language, default_country_code and metrics are optional values, with defaults 'en', nil and 'metric'.
Other
open_weather_api = OpenWeatherAPI::API.new api_key: ENV['OPEN_WEATHER_API_KEY'], language: 'es', units: 'metric'
# ...
Finally, you can use the different resources of the API:
NOTE: You can add manually any parameter you need for each request.
Current Weather
By city name:
json = open_weather_api.current city: 'Santa Cruz de Tenerife', country_code: 'es'
By city id:
json = open_weather_api.current id: 6360638
By multiple cities ids:
json = open_weather_api.current id: [6360638, 2511401]
By geolocation:
json = open_weather_api.current lon: -16.20302, lat: 28.53924
By zipcode:
json = open_weather_api.current zipcode: 38190, country_code: 'es'
By a geolocated rectangle:
json = open_weather_api.current rectangle: { topleft: { lat: -16.3319, lon: 28.5046 }, bottomright: { lat: -16.1972, lon: 28.4400}, zoom: 10 }
By a geolocated circle (WARNING: Unexpected behaviour by API):
json = open_weather_api.current circle: { lat: -16.3319, lon: 28.5046 }, cities_count: 2
You can also use ruby blocks to handle the response:
open_weather_api.current city: 'Santa Cruz de Tenerife', country_code: 'es' do |json|
puts JSON.pretty_generate(json)
end
For more information about the API, visit (http://openweathermap.org/current)[http://openweathermap.org/current].
Forecast
TODO.
Authors
This project has been developed by:
| Avatar | Name | Nickname | |
|---|---|---|---|
| Daniel Herzog | Wikiti | [email protected] |
Contributing
- Fork it ( http://github.com/wikiti/open-weather-api/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request