Class: YahooWeather::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo-weather/client.rb

Overview

The main client object through which the Yahoo! Weather service may be accessed.

Constant Summary collapse

@@API_URL =

the url with which we obtain weather information from yahoo

"http://weather.yahooapis.com/forecastrss"

Instance Method Summary collapse

Constructor Details

#initialize(api_url = @@API_URL) ⇒ Client

Returns a new instance of Client.



6
7
8
# File 'lib/yahoo-weather/client.rb', line 6

def initialize (api_url = @@API_URL)
  @api_url = api_url
end

Instance Method Details

#lookup_by_woeid(woeid, units = 'f') ⇒ Object

Returns a YahooWeather::Response object detailing the current weather information for the specified location.

The lookup requires the unique WOEID for the location whose weather is sought.. To find your WOEID, browse or search for your city from the Weather (weather.yahoo.com/) home page. The WOEID is in the URL for the forecast page for that city. You can also get the WOEID by entering your zip code on the home page. For example, if you search for Los Angeles on the Weather home page, the forecast page for that city is weather.yahoo.com/united-states/california/los-angeles-2442047/. The WOEID is 2442047.

units allows specifying whether to retrieve information in Fahrenheit as YahooWeather::Units::FAHRENHEIT, or Celsius as YahooWeather::Units::CELSIUS, and defaults to fahrenheit.



27
28
29
30
# File 'lib/yahoo-weather/client.rb', line 27

def lookup_by_woeid (woeid, units = 'f')
  url = @api_url + '?w=' + CGI.escape(woeid.to_s) + '&u=' + CGI.escape(units)
  _lookup(woeid, url)
end

#lookup_location(location, units = 'f') ⇒ Object

Returns a YahooWeather::Response object detailing the current weather information for the specified location.

NOTE: This method is deprecated as Yahoo has deprecated this non-WOEID-based lookup function. Please use the new lookup_by_woeid method instead.

location can be either a US zip code or a location code. Location codes can be looked up at weather.yahoo.com, where it will appear in the URL that results from searching on the city or zip code. For instance, searching on ‘Seattle, WA’ results in a URL ending in ‘USWA0395.html’, so the location code for Seattle is ‘USWA0395’.

units allows specifying whether to retrieve information in Fahrenheit as YahooWeather::Units::FAHRENHEIT, or Celsius as YahooWeather::Units::CELSIUS, and defaults to fahrenheit.



49
50
51
52
# File 'lib/yahoo-weather/client.rb', line 49

def lookup_location (location, units = 'f')
  url = @api_url + '?p=' + CGI.escape(location) + '&u=' + CGI.escape(units)
  _lookup(location, url)
end