Class: YahooWeather::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo_weather/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#unitsObject (readonly)

Returns the value of attribute units.



2
3
4
# File 'lib/yahoo_weather/client.rb', line 2

def units
  @units
end

#woeidObject (readonly)

Returns the value of attribute woeid.



2
3
4
# File 'lib/yahoo_weather/client.rb', line 2

def woeid
  @woeid
end

Instance Method Details

#fetch(woeid, units = YahooWeather::Units::FAHRENHEIT) ⇒ Object



4
5
6
7
8
9
# File 'lib/yahoo_weather/client.rb', line 4

def fetch(woeid, units = YahooWeather::Units::FAHRENHEIT)
  @units = units
  @woeid = woeid
  doc = Nokogiri::XML(read_xml)
  YahooWeather::Response.new(doc)
end

#fetch_by_location(location, units = YahooWeather::Units::FAHRENHEIT) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/yahoo_weather/client.rb', line 11

def fetch_by_location(location, units = YahooWeather::Units::FAHRENHEIT)
  url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.placefinder%20where%20text%3D%22#{::CGI.escape(location)}%22%20and%20gflags%3D%22R%22"
  xml = fetch_xml(url)
  doc = Nokogiri::XML(xml)
  woeid = doc.at('woeid').children.text
  fetch(woeid, units)
rescue
  nil
end