lib/weather-report/weather.rb in weather-report-0.3.6 vs lib/weather-report/weather.rb in weather-report-0.3.7
- old
+ new
@@ -1,31 +1,22 @@
# -*- coding: utf-8 -*-
module WeatherReport
- def self.cities
- proxy = Weather.parse_proxy(ENV["http_proxy"])
- doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml", :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass]))
- doc.xpath("//city").map{|i|
- i["title"]
- }
- end
-
class Weather
attr_reader :today, :tomorrow, :day_after_tomorrow
def initialize(city_id)
@uri = URI.parse("http://weather.livedoor.com/forecast/webservice/json/v1?city=#{city_id}")
end
# @return [String] the id of given city
def self.request_cityid(city_name)
+ raise ArgumentError, "City name must be String." unless city_name.kind_of?(String)
proxy = Weather.parse_proxy(ENV["http_proxy"])
doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml", :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass]))
doc.search("//city[@title='#{city_name}']").attr("id").value
rescue NoMethodError
raise WeatherReportError, "It seems like city #{city_name} does not exist.\nPlease look at http://weather.livedoor.com/forecast/rss/primary_area.xml for city list."
- rescue => e
- raise WeatherReportError
end
def self.parse_proxy(proxy)
# http://user:pass@host:port のように書かれていることを想定
# パスワードに@とか入ってる場合があるので一番後ろの@でだけsplitする