Module WeatherHacks::LWWS
In: lib/weatherhacks/lwws.rb

Methods

request  

Classes and Modules

Class WeatherHacks::LWWS::Celsius
Class WeatherHacks::LWWS::Copyright
Class WeatherHacks::LWWS::Error
Class WeatherHacks::LWWS::Fahrenheit
Class WeatherHacks::LWWS::Forecast
Class WeatherHacks::LWWS::Image
Class WeatherHacks::LWWS::Location
Class WeatherHacks::LWWS::PinpointLocation
Class WeatherHacks::LWWS::Provider
Class WeatherHacks::LWWS::Temperature

Constants

URL = URI.parse("http://weather.livedoor.com/forecast/webservice/rest/v1")

External Aliases

request -> []

Public Class methods

Returns a Forecast object.

city_id:city id
day::today, :tomorrow or :dayaftertomorrow

[Source]

     # File lib/weatherhacks/lwws.rb, line 129
129:     def request(city, day = :all)
130:       city_id = if city.kind_of?(String)
131:                   WeatherHacks::ForecastMap::CITY[city].id
132:                 else city end
133:       unless day.to_s =~ /today|tomorrow|dayaftertomorrow|all/
134:         raise ArgumentError, day
135:       end
136:       if day == :all
137:         return [ request(city, :today),
138:                  request(city, :tomorrow),
139:                  request(city, :dayaftertomorrow) ]
140:       end
141:       req = Net::HTTP::Get.new(path(city_id, day.to_s))
142:       http = Net::HTTP.new(URL.host)
143:       case res = http.request(req)
144:       when Net::HTTPSuccess
145:         Forecast.new(REXML::Document.new(res.body))
146:       else
147:         raise Error.new(res)
148:       end
149:     end

[Validate]