forecast ======== > Forecast Multi-API-Wrapper with unified model and integrated caching ## API Support * Open Weather Map * Yahoo RSS * Forecast.io * Wunderground ## Fetch #### Forecast.current( latitude, longitude ) Get the current weather for a specified location ```ruby forecast = Forecast.current(54.9999, 9.534) ``` #### Forecast.hourly( latitude, longitude ) Get hourly forecasts for a specified location ```ruby forecasts = Forecast.hourly(54.9999, 9.534) ``` #### Forecast.daily( latitude, longitude ) Get daily forecasts for a specified location ```ruby forecasts = Forecast.daily(54.9999, 9.534) ``` ### Collections #### ForecastCollection.select_time( date ) Fetches forecast for the specified date from a collection. ```ruby forecast = Forecast.daily(54.9999, 9.534).select_time(Time.now + (24 * 60 * 60) * 2) ``` ## Model
Name Description
condition Condition string identifier.
time DateTime of the forecast
icon Returns icon identifier
latitude Location coordinate latitude
longitude Location coordinate longitude
temperature Temperature
temperature_min Minimum Temperature
temperature_max Maximum Temperature
## Conditions
Code Name
100 Clear
200 Partly Cloudy
210 Cloudy
220 Mostly Cloudy
300 Light Rain
310 Rain
320 Heavy Rain
400 Light Snow
410 Snow
500 Storm
## Themes Bundled with the plugin is an icon-mapping for [weather_icons](http://erikflowers.github.io/weather-icons/) ## Rails Integration ##### Add weather-icons theme to your stylesheets ```erb <%= stylesheet_link_tag "http://cdnjs.cloudflare.com/ajax/libs/weather-icons/1.2/css/weather-icons.css", media: "all", "data-turbolinks-track" => true %> ``` ##### Create a forecast-helper ```ruby module ApplicationHelper def forecast(latitude, longitude, date) forecast = Forecast.daily(latitude, longitude).select_date(date) content_tag('span', content_tag('i', ' ', class: "forecast-icon " + forecast.icon) + " ".html_safe + content_tag('span', (forecast.temp.to_s + "°").html_safe, class: 'forecast-temp'), class: 'forecast') end end ``` ##### Create a view ```erb

Forecast Test

The weather of tomorrow in New York: <%= forecast(41.145495, -73.994901, Time.now + 60*60*24) %>

``` #### Example Configuration ```ruby # config/initializers/forecast.rb Forecast::configure do |config| config.config_file = Rails.root.to_s + "/config/forecast.yml" config.cache = { expire: 1 * 60 * 60, url: "redis://xxx/" } end ``` ```yml # config/forecast.yml forecast: temperature: celsius theme: custom_theme themes: custom_theme: Clear: 'icon-clear' Light Rain: 'icon-rain' Rain: 'icon-rain' Heavy Rain: 'icon-rain' Partly Cloudy: 'icon-cloudy' Cloudy: 'icon-cloudy' Mostly Cloudy: 'icon-cloudy' Light Snow: 'icon-snow' Snow: 'icon-snow' Heavy Snow: 'icon-snow' Thunderstorm: 'icon-thunderstorm' ``` ## Command Line Interface ```cli Usage: forecast COMMAND [OPTIONS] Commands current: get current weather [default] daily: get daily forecasts hourly: get hourly forecasts Options -l, --location LAT,LNG Location [required] -p, --provider PROVIDER Supported API Providers: forecast_io, open_weather_map, wunderground, yahoo -a, --api_key API_KEY Apply an api key if neccessary -s, --scale SCALE Scale: one of celsius, fahrenheit or kelvin -h, --help Displays Help ``` ## Run Tests To run the tests execute `rspec spec` from the command line ```cli rspec spec ``` ## Changelog See the [Changelog](CHANGELOG.md) for recent enhancements, bugfixes and deprecations.