lib/meteo/meteo.rb in meteo-1.0.2 vs lib/meteo/meteo.rb in meteo-1.1.0
- old
+ new
@@ -1,19 +1,24 @@
require 'net/http'
+require 'json'
class Meteo
- OPEN_WEATHER_MAP_SERVICE_URL = 'http://api.openweathermap.org/data/2.5/weather'
+ OPEN_WEATHER_MAP_SERVICE_URL = 'http://api.openweathermap.org/data/2.5'
attr_reader :url
- def initialize
- @url = OPEN_WEATHER_MAP_SERVICE_URL
+ def initialize(forecast=false)
+ if forecast
+ @url = "#{OPEN_WEATHER_MAP_SERVICE_URL}/forecast/daily"
+ else
+ @url = "#{OPEN_WEATHER_MAP_SERVICE_URL}/weather"
+ end
end
def quote location, units
- quote_url = "#{url}?q=#{location}%20nj&units=#{units}"
+ quote_url = "#{url}?q=#{location}&units=#{units}"
uri = URI.parse(URI.escape(quote_url))
- Net::HTTP.get(uri)
+ JSON.parse(Net::HTTP.get(uri))
end
end
\ No newline at end of file