Class: YahooWeather::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
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(app_id = @@APP_ID, api_url = @@API_URL) ⇒ Client

Uncomment and fill in below section for hard embedded connection @@APP_ID = “LIST_FREE_YAHOO_API_HERE”



11
12
13
14
# File 'lib/yahoo-weather/client.rb', line 11

def initialize (app_id = @@APP_ID,api_url = @@API_URL)
  @api_url = api_url
  @app_id = app_id
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.



33
34
35
36
# File 'lib/yahoo-weather/client.rb', line 33

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_zip(zip, units = 'f') ⇒ Object

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

zip MUST BE A US ZIP CODE

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



47
48
49
50
# File 'lib/yahoo-weather/client.rb', line 47

def lookup_zip(zip, units = 'f')
  woeid = woe_lookup(zip)
  lookup_by_woeid(woeid)
end