Module: Weather
- Defined in:
- lib/weather-api.rb,
lib/weather-api/wind.rb,
lib/weather-api/image.rb,
lib/weather-api/units.rb,
lib/weather-api/utils.rb,
lib/weather-api/version.rb,
lib/weather-api/forecast.rb,
lib/weather-api/location.rb,
lib/weather-api/response.rb,
lib/weather-api/astronomy.rb,
lib/weather-api/condition.rb,
lib/weather-api/atmosphere.rb
Defined Under Namespace
Classes: Astronomy, Atmosphere, Condition, Forecast, Image, Location, Response, Units, Utils, Wind
Constant Summary collapse
- ROOT =
Yahoo! Weather info endpoint
"http://query.yahooapis.com/v1/public/yql"
- VERSION =
"1.4.0"
Class Method Summary collapse
-
.lookup(woeid, unit = Units::CELSIUS) ⇒ Object
Public: Looks up current weather information using WOEID.
-
.lookup_by_location(location, unit = Units::CELSIUS) ⇒ Object
Public: Looks up current weather information using a location string.
Class Method Details
.lookup(woeid, unit = Units::CELSIUS) ⇒ Object
Public: Looks up current weather information using WOEID
woeid - Int - Where On Earth IDentifier – unique ID for
location to get weather data for. To find
a WOEID, refer to Yahoo!'s documentation
at http://developer.yahoo.com/weather/
unit - system of measurement to use. Two acceptable inputs:
'c' - Celsius/Metric measurements
'f' - Fahrenheit/Imperial measurements.
To make this easier, you can use the Weather::Units::FAHRENHEIT and
Weather::Units::CELSIUS constants. Defaults to Celsius
Returns a Weather::Response object containing forecast
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/weather-api.rb', line 37 def lookup(woeid, unit = Units::CELSIUS) acceptable_units = [Units::CELSIUS, Units::FAHRENHEIT] unit = Units::CELSIUS unless acceptable_units.include?(unit) url = ROOT + "?q=select%20*%20from%20weather.forecast%20" url += "where%20woeid%3D#{woeid}%20and%20u%3D'#{unit}'&format=json" doc = get_response url Response.new woeid, url, doc end |
.lookup_by_location(location, unit = Units::CELSIUS) ⇒ Object
Public: Looks up current weather information using a location string
location - String - A location name. ‘City, state, country’
Examples: Nome, AK
San Francisco, CA, USA
Berlin, Germany
toronto, ca
unit - system of measurement to use. Two acceptable inputs:
'c' - Celsius/Metric measurements
'f' - Fahrenheit/Imperial measurements.
To make this easier, you can use the Weather::Units::FAHRENHEIT and
Weather::Units::CELSIUS constants. Defaults to Celsius
Returns a Weather::Response object containing forecast
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/weather-api.rb', line 64 def lookup_by_location(location, unit = Units::CELSIUS) acceptable_units = [Units::CELSIUS, Units::FAHRENHEIT] unit = Units::CELSIUS unless acceptable_units.include?(unit) # per the documentation here: https://developer.yahoo.com/weather/ # can look up the woeid via geo places api from location url = ROOT + "?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='#{location}') and u='#{unit}'&format=json" url = URI.escape(url) doc = get_response url Response.new location, url, doc end |