README.rdoc

Path: README.rdoc
Last Update: Sat Jul 18 20:31:52 +0100 2009

weather_report

Homepage:www.cordinc.com/projects/weather_report
Author:Charles Cordingley
Copyright:(c) 2009 Charles Cordingley
License:MIT

DESCRIPTION:

Connect to the BBC Backstage (backstage.bbc.co.uk) weather API and get weather observations and forecasts for thousands of cities worldwide. No login is required to the BBC for use.

TODO

  • Allow weather to be shown in either metric or imperial units (currently only metric)
  • Be able to seach or lookup location ids
  • Add weather sources other than the BBC

SYNOPSIS:

After requiring the library, create a WeatherReport object with a BBC weather location id:

 require 'weather_report'
 # 8 is the BBC Backstage weather code for London, UK
 londonWeather = WeatherReport.new(8)

Then you can get the observations or forecasts for that location:

 londonWeather.observation.temperature
 londonWeather.forecast.for_tomorrow.max_temperature

Calls to the observation or forecast data after the first call for a location will just return return cached data. Use force_reload = true on the call to force the data to be reloaded from the BBC.

 # use the cached data
 londonWeather.observation.reading_date
 # reload the data
 londonWeather.observation(force_reload = true).reading_date

Forecasts can be specified in a number of ways:

 londonWeather.forecast.for_tomorrow.max_temperature
 londonWeather.forecast.for_today.max_temperature
 # also today
 londonWeather.forecast.for(Date.today).max_temperature
 # day after tomorrow
 londonWeather.forecast.for(Date.today+2).max_temperature
 # The date can also be specified as a date string
 londonWeather.forecast.for("2009-05-06").max_temperature
 # The underlying structure is an array, so you can just index into it. The below is the same as today
 londonWeather.forecast[0].max_temperature

The full set of attributes is:

 londonWeather.observation.reading_date
 londonWeather.observation.name
 londonWeather.observation.country
 londonWeather.observation.latitude
 londonWeather.observation.longtitude
 londonWeather.observation.temperature
 londonWeather.observation.wind_speed
 londonWeather.observation.wind_direction
 londonWeather.observation.humidity
 londonWeather.observation.pressure
 londonWeather.observation.pressure_state
 londonWeather.observation.visibility
 londonWeather.observation.humidity
 londonWeather.observation.description

 londonWeather.forecast.reading_date
 londonWeather.forecast.name
 londonWeather.forecast.country
 londonWeather.forecast.latitude
 londonWeather.forecast.longtitude
 londonWeather.forecast.image_url
 londonWeather.forecast.for_today.date
 londonWeather.forecast.for_today.max_temperature
 londonWeather.forecast.for_today.min_temperature
 londonWeather.forecast.for_today.wind_speed
 londonWeather.forecast.for_today.wind_direction
 londonWeather.forecast.for_today.humidity
 londonWeather.forecast.for_today.pressure
 londonWeather.forecast.for_today.visibility
 londonWeather.forecast.for_today.humidity
 londonWeather.forecast.for_today.description
 londonWeather.forecast.for_today.advance_days

REQUIREMENTS:

The only external dependencies are REXML and net/http which are included as part of most Ruby installations.

INSTALL:

The weather_report library is distributed itself as a RubyGem and is available immediately after installation.

  sudo gem install weather_report

Alternately, download the gem here or the tgz here and install manually.

LICENSE:

(The MIT License)

Copyright (c) 2009 Charles Cordingley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[Validate]