Module: WeatherHacks::LWWS

Defined in:
lib/weatherhacks/lwws.rb

Defined Under Namespace

Classes: Celsius, Copyright, Error, Fahrenheit, Forecast, Image, Location, PinpointLocation, Provider, Temperature

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.path(city_id, day) ⇒ Object

:nodoc:



9
10
11
# File 'lib/weatherhacks/lwws.rb', line 9

def self.path(city_id, day) #:nodoc:
  URL.path + "?city=#{city_id}&day=#{day}"
end

.request(city_id, day = :today) ⇒ Object

Returns a Forecast object.

city_id

city id

day

:today, :tomorrow or :dayaftertomorrow



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/weatherhacks/lwws.rb', line 127

def self.request(city_id, day = :today)
  unless day == :today or day == :tomorrow or day == :dayaftertomorrow
    raise ArgumentError, day
  end
  req = Net::HTTP::Get.new(path(city_id, day.to_s))
  http = Net::HTTP.new(URL.host)
  case res = http.request(req)
  when Net::HTTPSuccess
    Forecast.new(REXML::Document.new(res.body))
  else
    raise Error.new(res)
  end
end