Accuweather
A simple wrapper around the accuweather web API written in Ruby
Get weather information for cities around the world. Includes current current conditions for temperature, pressure and humidity. Forecasts include temperature highs, lows, "real feels", UV, wind speed and direction, rain, snow, ice probabilities and amounts. The web API returns seven days of forecasts with estimates for both day and nighttime.
Also includes local times for the rise and set of celestial bodies in our solar system including the sun, moon, mercury, venus, mars, jupiter, saturn, uranus, neptune and pluto.
Installation
Add this line to your application's Gemfile:
gem 'accuweather'
And then execute:
$ bundle
Or install it yourself as:
$ gem install accuweather
Usage
Search for a city location to determine its id:
location_array = Accuweather.city_search(name: 'vancouver')
vancouver = location_array.first
vancouver.id
vancouver.city
vancouver.state
vancouver.latitude
vancouver.longitude
Search for weather conditions for a given location id:
current_weather = Accuweather.get_conditions(location_id: 'cityId:53286').current
current_weather.temperature
current_weather.weather_text
current_weather.pressure
current_weather.humidity
current_weather.cloud_cover
Get forecast details:
weather_forecast = Accuweather.get_conditions(location_id: 'cityId:53286').forecast
last_forecast_day = weather_forecast.last
last_forecast_day.date
last_forecast_day.day_of_week
last_forecast_day.sunrise
last_forecast_day.sunset
weather_forecast.map(&:date)
weather_forecast.map(&:daytime).map(&:high_temperature)
weather_forecast.map(&:nighttime).map(&:low_temperature)
See Accuview::Conditions::ForecastWeather
class for a full list of attributes for daytime and nighttime forecasts.
Get the units for the conditions:
units = Accuweather.get_conditions(location_id: 'cityId:53286').units
units.temperature
units.distance
units.speed
Get more information on the location including time and time zone:
local = Accuweather.get_conditions(location_id: 'cityId:53286').local
local.time
local.time_zone
local.time_zone_abbreviation
English units are returned by default, but metric results are available:
Accuweather.get_conditions(location_id: 'cityId:53286', metric: true)
Each Accuweather::Conditions
object implements a to_s
method that displays all attribute
name, value pairs. This makes it easy to explore the API. For example:
Accuweather.get_conditions(location_id: 'cityId:53286').local.to_s
Get local times for the rise and set of celestial bodies in our solar system:
planets = Accuweather.get_conditions(location_id: 'cityId:53286').planets
planets.sunrise
planets.moonrise
planets.sunset
planets.marsrise
planets.plutoset
Development
Run rake
to run the tests
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/accuweather.