diff --git a/Gemfile.lock b/Gemfile.lock index b14d14e..b57d996 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - yahoo_weatherman (2.0.0) + yahoo_weatherman (2.0.3) nokogiri GEM diff --git a/lib/yahoo_weatherman.rb b/lib/yahoo_weatherman.rb index 5a47a55..6c74e31 100644 --- a/lib/yahoo_weatherman.rb +++ b/lib/yahoo_weatherman.rb @@ -15,7 +15,7 @@ module Weatherman VERSION = '2.0.2' - URI = 'http://xml.weather.yahoo.com/forecastrss' + URI = 'https://query.yahooapis.com/v1/public/yql?q=' # = Client # @@ -44,7 +44,7 @@ def initialize(options = {}) # Looks up weather by woeid. # def lookup_by_woeid(woeid) - raw = get request_url(woeid) + raw = get woeid_query_url(woeid) Response.new(raw, options[:lang]) end @@ -52,18 +52,18 @@ def lookup_by_woeid(woeid) # Looks up weather by location. # def lookup_by_location(location) - lookup = WoeidLookup.new - woeid = lookup.get_woeid(location) - lookup_by_woeid(woeid) + raw = get location_query_url(location) + Response.new(raw, options[:lang]) end private - def request_url(woeid) - @uri + query_string(woeid) + + def woeid_query_url(woeid) + "#{URI}select%20*%20from%20weather.forecast%20where%20woeid%20%3D%20#{woeid}%20and%20u%20%3D%20'#{degrees_units}'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" end - def query_string(woeid) - "?w=#{woeid}&u=#{degrees_units}" + def location_query_url(location) + "#{URI}select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22#{::CGI.escape(location)}%22)%20and%20u%20%3D%20'#{degrees_units}'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" end def degrees_units diff --git a/lib/yahoo_weatherman/image.rb b/lib/yahoo_weatherman/image.rb index be7d1b5..56f493f 100644 --- a/lib/yahoo_weatherman/image.rb +++ b/lib/yahoo_weatherman/image.rb @@ -10,7 +10,7 @@ def initialize(doc) end def [](attr) - @image_root.xpath(attr).first.content + @image_root[attr] end end end diff --git a/lib/yahoo_weatherman/response.rb b/lib/yahoo_weatherman/response.rb index 2394f4a..156851e 100644 --- a/lib/yahoo_weatherman/response.rb +++ b/lib/yahoo_weatherman/response.rb @@ -1,4 +1,7 @@ # coding: utf-8 + +require 'json' + module Weatherman # = Response @@ -11,7 +14,7 @@ class Response attr_accessor :document_root def initialize(raw, language = nil) - @document_root = Nokogiri::XML(raw).xpath('rss/channel') + @document_root = JSON.parse(raw).dig('query', 'results', 'channel') @i18n = Weatherman::I18N.new(language) end @@ -25,20 +28,20 @@ def initialize(raw, language = nil) # condition['date'] => # # def condition - condition = item_attribute('yweather:condition') + condition = item_attribute('condition') translate! do_convertions(condition, [:code, :to_i], [:temp, :to_i], [:date, :to_date], :text) end - # + # # Wind's details: # # wind = response.wind - # wind['chill'] => 21 - # wind['direction'] => 340 + # wind['chill'] => 21 + # wind['direction'] => 340 # wind['chill'] => 9.66 # def wind - do_convertions(attribute('yweather:wind'), [:chill, :to_i], [:direction, :to_i], [:speed, :to_f]) + do_convertions(attribute('wind'), [:chill, :to_i], [:direction, :to_i], [:speed, :to_f]) end # @@ -53,7 +56,7 @@ def wind # def forecasts convertions = [[:date, :to_date], [:low, :to_i], [:high, :to_i], [:code, :to_i], :day, :text] - item_attribute('yweather:forecast').collect do |forecast| + item_attribute('forecast').collect do |forecast| translate! do_convertions(forecast, *convertions) end end @@ -67,7 +70,7 @@ def forecasts # location['city'] => Belo Horizonte # def location - translate! attribute('yweather:location') + translate! attribute('location') end # Units: @@ -79,7 +82,7 @@ def location # units['speed'] => "km/h" # def units - attribute('yweather:units') + attribute('units') end # @@ -90,22 +93,22 @@ def units # astronomy['sunset'] => "7:20 pm" # def astronomy - attribute('yweather:astronomy') + attribute('astronomy') end # # Atmosphere : # - # atmosphere = response.atmosphere + # atmosphere = response.atmosphere # atmosphere['humidity'] => "62" # atmosphere['visibility'] => "9.99" # atmosphere['pressure'] => "982.05" # atmosphere['rising'] => "0" # def atmosphere - atm = attribute('yweather:atmosphere') + atm = attribute('atmosphere') do_convertions(atm, [:humidity, :to_f], [:visibility, :to_f], [:pressure, :to_f], [:rising, :to_f]) - end + end # # Latitude: @@ -115,7 +118,7 @@ def latitude geo_attribute('lat') end - # + # # Longitude; # # response.longitude => -45.32 @@ -139,7 +142,7 @@ def image end # - # Description image. You might gonna need this if you have to customize the + # Description image. You might gonna need this if you have to customize the # forecast summary. # def description_image @@ -148,9 +151,10 @@ def description_image # # A short HTML snippet (raw text) with a simple weather description. - # + # def description - text_attribute('description') + doc = Nokogiri::XML.fragment(item_attribute('description')) + doc.content end alias :summary :description @@ -159,25 +163,21 @@ def description # if you have to walk through its nodes. # def parsed_description - @parsed_description ||= Nokogiri::HTML(description) + @parsed_description ||= Nokogiri::HTML(description) end private def attribute(attr, root = @document_root) - elements = root.xpath(attr) + elements = root[attr] elements.size == 1 ? elements.first : elements end def item_attribute(attr) - attribute(attr, document_root.xpath('item').first) + attribute(attr, @document_root['item']) end def geo_attribute(attr) - item_attribute('geo:' + attr).children.first.text.to_f - end - - def text_attribute(attr) - item_attribute(attr).content + item_attribute(attr).to_f end def do_convertions(attributes, *pairs) @@ -194,8 +194,7 @@ def convert(value, method) end def translate!(attributes) - @i18n.translate! attributes + @i18n.translate! attributes end end end - diff --git a/spec/files/belo_horizonte_c.json b/spec/files/belo_horizonte_c.json new file mode 100644 index 0000000..7ace22f --- /dev/null +++ b/spec/files/belo_horizonte_c.json @@ -0,0 +1,149 @@ +{ + "query": { + "count": 1, + "created": "2016-05-22T13:22:34Z", + "lang": "en-US", + "results": { + "channel": { + "units": { + "distance": "km", + "pressure": "mb", + "speed": "km/h", + "temperature": "C" + }, + "title": "Yahoo! Weather - Belo Horizonte, MG, BR", + "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-455821/", + "description": "Yahoo! Weather for Belo Horizonte, MG, BR", + "language": "en-us", + "lastBuildDate": "Sun, 22 May 2016 10:22 AM BRT", + "ttl": "60", + "location": { + "city": "Belo Horizonte", + "country": "Brazil", + "region": " MG" + }, + "wind": { + "chill": "72", + "direction": "68", + "speed": "11.27" + }, + "atmosphere": { + "humidity": "83", + "pressure": "31290.24", + "rising": "0", + "visibility": "25.91" + }, + "astronomy": { + "sunrise": "6:20 am", + "sunset": "5:25 pm" + }, + "image": { + "title": "Yahoo! Weather", + "width": "142", + "height": "18", + "link": "http://weather.yahoo.com", + "url": "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif" + }, + "item": { + "title": "Conditions for Belo Horizonte, MG, BR at 09:00 AM BRT", + "lat": "-19.899309", + "long": "-43.964352", + "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-455821/", + "pubDate": "Sun, 22 May 2016 09:00 AM BRT", + "condition": { + "code": "32", + "date": "Sun, 22 May 2016 09:00 AM BRT", + "temp": "22", + "text": "Sunny" + }, + "forecast": [ + { + "code": "32", + "date": "22 May 2016", + "day": "Sun", + "high": "26", + "low": "16", + "text": "Sunny" + }, + { + "code": "47", + "date": "23 May 2016", + "day": "Mon", + "high": "26", + "low": "16", + "text": "Scattered Thunderstorms" + }, + { + "code": "28", + "date": "24 May 2016", + "day": "Tue", + "high": "21", + "low": "16", + "text": "Mostly Cloudy" + }, + { + "code": "30", + "date": "25 May 2016", + "day": "Wed", + "high": "21", + "low": "14", + "text": "Partly Cloudy" + }, + { + "code": "30", + "date": "26 May 2016", + "day": "Thu", + "high": "24", + "low": "13", + "text": "Partly Cloudy" + }, + { + "code": "30", + "date": "27 May 2016", + "day": "Fri", + "high": "25", + "low": "15", + "text": "Partly Cloudy" + }, + { + "code": "26", + "date": "28 May 2016", + "day": "Sat", + "high": "23", + "low": "16", + "text": "Cloudy" + }, + { + "code": "47", + "date": "29 May 2016", + "day": "Sun", + "high": "23", + "low": "16", + "text": "Scattered Thunderstorms" + }, + { + "code": "34", + "date": "30 May 2016", + "day": "Mon", + "high": "21", + "low": "15", + "text": "Mostly Sunny" + }, + { + "code": "32", + "date": "31 May 2016", + "day": "Tue", + "high": "26", + "low": "13", + "text": "Sunny" + } + ], + "description": "\n
\nCurrent Conditions:\n
Sunny\n
\n
\nForecast:\n
Sun - Sunny. High: 26Low: 16\n
Mon - Scattered Thunderstorms. High: 26Low: 16\n
Tue - Mostly Cloudy. High: 21Low: 16\n
Wed - Partly Cloudy. High: 21Low: 14\n
Thu - Partly Cloudy. High: 24Low: 13\n
\n
\nFull Forecast at Yahoo! Weather\n
\n
\n(provided by The Weather Channel)\n
\n]]>", + "guid": { + "isPermaLink": "false" + } + } + } + } + } +} diff --git a/spec/files/belo_horizonte_c.rss b/spec/files/belo_horizonte_c.rss deleted file mode 100644 index 9942173..0000000 --- a/spec/files/belo_horizonte_c.rss +++ /dev/null @@ -1,49 +0,0 @@ - - - - -Yahoo! Weather - Belo Horizonte, BR -http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html -Yahoo! Weather for Belo Horizonte, BR -en-us -Sat, 13 Mar 2010 6:00 pm LST -60 - - - - - - - -Yahoo! Weather -142 -18 -http://weather.yahoo.com -http://l.yimg.com/a/i/us/nws/th/main_142b.gif - - - -Conditions for Belo Horizonte, BR at 6:00 pm LST --19.95 --43.93 -http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html -Sat, 13 Mar 2010 6:00 pm LST - -
-Current Conditions:
-Mostly Cloudy, 28 C
-
Forecast:
-Sat - Showers. High: 27 Low: 18
-Sun - Scattered Thunderstorms. High: 27 Low: 18
-
-Full Forecast at Yahoo! Weather

-(provided by The Weather Channel)
-]]>
- - -BRXX0033_2010_03_13_18_00_LST -
- -
-
diff --git a/spec/files/belo_horizonte_f.json b/spec/files/belo_horizonte_f.json new file mode 100644 index 0000000..1035c17 --- /dev/null +++ b/spec/files/belo_horizonte_f.json @@ -0,0 +1,149 @@ +{ + "query": { + "count": 1, + "created": "2016-05-22T13:24:04Z", + "lang": "en-US", + "results": { + "channel": { + "units": { + "distance": "mi", + "pressure": "in", + "speed": "mph", + "temperature": "F" + }, + "title": "Yahoo! Weather - Belo Horizonte, MG, BR", + "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-455821/", + "description": "Yahoo! Weather for Belo Horizonte, MG, BR", + "language": "en-us", + "lastBuildDate": "Sun, 22 May 2016 10:24 AM BRT", + "ttl": "60", + "location": { + "city": "Belo Horizonte", + "country": "Brazil", + "region": " MG" + }, + "wind": { + "chill": "72", + "direction": "68", + "speed": "7" + }, + "atmosphere": { + "humidity": "83", + "pressure": "924.0", + "rising": "0", + "visibility": "16.1" + }, + "astronomy": { + "sunrise": "6:20 am", + "sunset": "5:25 pm" + }, + "image": { + "title": "Yahoo! Weather", + "width": "142", + "height": "18", + "link": "http://weather.yahoo.com", + "url": "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif" + }, + "item": { + "title": "Conditions for Belo Horizonte, MG, BR at 09:00 AM BRT", + "lat": "-19.899309", + "long": "-43.964352", + "link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-455821/", + "pubDate": "Sun, 22 May 2016 09:00 AM BRT", + "condition": { + "code": "32", + "date": "Sun, 22 May 2016 09:00 AM BRT", + "temp": "72", + "text": "Sunny" + }, + "forecast": [ + { + "code": "32", + "date": "22 May 2016", + "day": "Sun", + "high": "80", + "low": "61", + "text": "Sunny" + }, + { + "code": "47", + "date": "23 May 2016", + "day": "Mon", + "high": "80", + "low": "62", + "text": "Scattered Thunderstorms" + }, + { + "code": "28", + "date": "24 May 2016", + "day": "Tue", + "high": "70", + "low": "62", + "text": "Mostly Cloudy" + }, + { + "code": "30", + "date": "25 May 2016", + "day": "Wed", + "high": "71", + "low": "58", + "text": "Partly Cloudy" + }, + { + "code": "30", + "date": "26 May 2016", + "day": "Thu", + "high": "76", + "low": "56", + "text": "Partly Cloudy" + }, + { + "code": "30", + "date": "27 May 2016", + "day": "Fri", + "high": "77", + "low": "60", + "text": "Partly Cloudy" + }, + { + "code": "26", + "date": "28 May 2016", + "day": "Sat", + "high": "75", + "low": "62", + "text": "Cloudy" + }, + { + "code": "47", + "date": "29 May 2016", + "day": "Sun", + "high": "74", + "low": "61", + "text": "Scattered Thunderstorms" + }, + { + "code": "34", + "date": "30 May 2016", + "day": "Mon", + "high": "71", + "low": "59", + "text": "Mostly Sunny" + }, + { + "code": "32", + "date": "31 May 2016", + "day": "Tue", + "high": "79", + "low": "57", + "text": "Sunny" + } + ], + "description": "\n
\nCurrent Conditions:\n
Sunny\n
\n
\nForecast:\n
Sun - Sunny. High: 80Low: 61\n
Mon - Scattered Thunderstorms. High: 80Low: 62\n
Tue - Mostly Cloudy. High: 70Low: 62\n
Wed - Partly Cloudy. High: 71Low: 58\n
Thu - Partly Cloudy. High: 76Low: 56\n
\n
\nFull Forecast at Yahoo! Weather\n
\n
\n(provided by The Weather Channel)\n
\n]]>", + "guid": { + "isPermaLink": "false" + } + } + } + } + } +} diff --git a/spec/files/belo_horizonte_f.rss b/spec/files/belo_horizonte_f.rss deleted file mode 100644 index 5a89689..0000000 --- a/spec/files/belo_horizonte_f.rss +++ /dev/null @@ -1,49 +0,0 @@ - - - - -Yahoo! Weather - Belo Horizonte, BR -http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_f.html -Yahoo! Weather for Belo Horizonte, BR -en-us -Thu, 18 Mar 2010 12:00 am LST -60 - - - - - - - -Yahoo! Weather -142 -18 -http://weather.yahoo.com -http://l.yimg.com/a/i/us/nws/th/main_142b.gif - - - -Conditions for Belo Horizonte, BR at 12:00 am LST --19.95 --43.93 -http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_f.html -Thu, 18 Mar 2010 12:00 am LST - -
-Current Conditions:
-Fair, 66 F
-
Forecast:
-Thu - Showers. High: 75 Low: 63
-Fri - Scattered Thunderstorms. High: 79 Low: 63
-
-Full Forecast at Yahoo! Weather

-(provided by The Weather Channel)
-]]>
- - -BRXX0033_2010_03_18_0_00_LST -
- -
-
diff --git a/spec/files/test_i18n.yml b/spec/files/test_i18n.yml index 9b95f15..b331920 100644 --- a/spec/files/test_i18n.yml +++ b/spec/files/test_i18n.yml @@ -51,7 +51,7 @@ locations: Brazil: Brasil Belo Horizonte: Santa Luzia - MG: Minas Gerais + " MG": Minas Gerais forecasts: days: diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f63839f..69b6496 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,21 +7,23 @@ require 'rspec' def celsius_fixture - filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_c.rss"])) + filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_c.json"])) File.read filepath end def fahrenheight_fixture - filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_f.rss"])) + filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_f.json"])) File.read filepath end FakeWeb.allow_net_connect = false -FakeWeb.register_uri(:get, "http://xml.weather.yahoo.com/forecastrss?w=455821&u=c", :body => celsius_fixture) -FakeWeb.register_uri(:get, "http://xml.weather.yahoo.com/forecastrss?w=455821&u=f", :body => fahrenheight_fixture) -FakeWeb.register_uri(:get, "http://xml.weather.yahoo.com/forecastrss?w=123456&u=f", :body => celsius_fixture) -FakeWeb.register_uri(:get, "http://xml.weather.yahoo.com/forecastrss?w=4729347&u=c", :body => celsius_fixture) -FakeWeb.register_uri(:get, "http://xml.weather.yahoo.com/forecastrss?w=12786745&u=c", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%20455821%20and%20u%20%3D%20'c'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%20455821%20and%20u%20%3D%20'f'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => fahrenheight_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%20123456%20and%20u%20%3D%20'f'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%204729347%20and%20u%20%3D%20'c'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%2012786745%20and%20u%20%3D%20'c'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22orange%22)%20and%20u%20%3D%20%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) +FakeWeb.register_uri(:get, "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%2278923%22)%20and%20u%20%3D%20%27c%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", :body => celsius_fixture) module YAML class << self diff --git a/spec/yahoo_weatherman/i18n_spec.rb b/spec/yahoo_weatherman/i18n_spec.rb index 722405d..3b71326 100644 --- a/spec/yahoo_weatherman/i18n_spec.rb +++ b/spec/yahoo_weatherman/i18n_spec.rb @@ -7,7 +7,7 @@ end it 'should translate the conditions details' do - @response.condition['text'].should == 'Predominantemente Nublado' + @response.condition['text'].should == 'Ensolarado' end it 'should translate the location details' do @@ -17,11 +17,9 @@ end it 'should translate the forecasts details' do - @response.forecasts.first['text'].should == 'Chuva' - @response.forecasts.last['text'].should == 'Tempestades Intermitentes' - @response.forecasts.first['day'].should == 'Sábado' - @response.forecasts.last['day'].should == 'Domingo' + @response.forecasts.first['text'].should == 'Ensolarado' + @response.forecasts.last['text'].should == 'Ensolarado' + @response.forecasts.first['day'].should == 'Domingo' + @response.forecasts.last['day'].should == 'Terça-feira' end end - - diff --git a/spec/yahoo_weatherman/response_spec.rb b/spec/yahoo_weatherman/response_spec.rb index 089f181..82f6f57 100644 --- a/spec/yahoo_weatherman/response_spec.rb +++ b/spec/yahoo_weatherman/response_spec.rb @@ -8,15 +8,15 @@ it 'should provide a location' do @response.location['city'].should == 'Belo Horizonte' - @response.location['region'].should == 'MG' + @response.location['region'].should == ' MG' @response.location['country'].should == 'Brazil' end it 'should provide a weather condition' do - @response.condition['code'].should == 28 - @response.condition['temp'].should == 28 - @response.condition['text'].should == 'Mostly Cloudy' - @response.condition['date'].should == DateTime.parse('Sat, 13 Mar 2010 6:00 pm LST') + @response.condition['code'].should == 32 + @response.condition['temp'].should == 22 + @response.condition['text'].should == 'Sunny' + @response.condition['date'].should == DateTime.parse('Sun, 22 May 2016 09:00 AM BRT') end it 'should provide the units used' do @@ -27,58 +27,67 @@ end it 'should provide information about the wind' do - @response.wind['chill'].should == 28 - @response.wind['direction'].should == 340 - @response.wind['speed'].should == 9.66 + @response.wind['chill'].should == 72 + @response.wind['direction'].should == 68 + @response.wind['speed'].should == 11.27 end it 'should provide astronomy information' do - @response.astronomy['sunrise'].should == '5:57 am' - @response.astronomy['sunset'].should == '6:13 pm' + @response.astronomy['sunrise'].should == '6:20 am' + @response.astronomy['sunset'].should == '5:25 pm' end - + it 'should provide atmosphere information' do - @response.atmosphere['humidity'].should == 62 - @response.atmosphere['visibility'].should == 9.99 - @response.atmosphere['pressure'].should == 982.05 - @response.atmosphere['rising'].should be_zero + @response.atmosphere['humidity'].should == 83.0 + @response.atmosphere['visibility'].should == 25.91 + @response.atmosphere['pressure'].should == 31290.24 + @response.atmosphere['rising'].should be_zero end it 'should get the next 2 forecasts' do first = @response.forecasts.first - first['day'].should == 'Sat' - first['date'].should == Date.parse('13 Mar 2010') - first['low'].should == 18 - first['high'].should == 27 - first['text'].should == 'Showers' - first['code'].should == 11 + first['day'].should == 'Sun' + first['date'].should == Date.parse('22 May 2016') + first['low'].should == 16 + first['high'].should == 26 + first['text'].should == 'Sunny' + first['code'].should == 32 last = @response.forecasts.last - last['day'].should == 'Sun' - last['date'].should == Date.parse('14 Mar 2010') - last['low'].should == 18 - last['high'].should == 27 - last['text'].should == 'Scattered Thunderstorms' - last['code'].should == 38 + last['day'].should == 'Tue' + last['date'].should == Date.parse('31 May 2016') + last['low'].should == 13 + last['high'].should == 26 + last['text'].should == 'Sunny' + last['code'].should == 32 end it 'should provide latitude and longitude' do - @response.latitude.should == -19.95 - @response.longitude.should == -43.93 + @response.latitude.should == -19.899309 + @response.longitude.should == -43.964352 end it 'should provide a description' do description = <<-DESCRIPTION - -
-Current Conditions:
-Mostly Cloudy, 28 C
-
Forecast:
-Sat - Showers. High: 27 Low: 18
-Sun - Scattered Thunderstorms. High: 27 Low: 18
-
-Full Forecast at Yahoo! Weather

-(provided by The Weather Channel)
+ +
+Current Conditions: +
Sunny +
+
+Forecast: +
Sun - Sunny. High: 26Low: 16 +
Mon - Scattered Thunderstorms. High: 26Low: 16 +
Tue - Mostly Cloudy. High: 21Low: 16 +
Wed - Partly Cloudy. High: 21Low: 14 +
Thu - Partly Cloudy. High: 24Low: 13 +
+
+Full Forecast at Yahoo! Weather +
+
+(provided by The Weather Channel) +
DESCRIPTION @response.description.should == description @@ -91,12 +100,12 @@ image['height'].should == 18 image['title'].should == 'Yahoo! Weather' image['link'].should == 'http://weather.yahoo.com' - image['url'].should == 'http://l.yimg.com/a/i/us/nws/th/main_142b.gif' + image['url'].should == 'http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif' end it 'should provide the forecast description icon' do image = @response.description_image - image['src'].should == 'http://l.yimg.com/a/i/us/we/52/28.gif' + image['src'].should == 'http://l.yimg.com/a/i/us/we/52/32.gif' end context 'using fahrenheiht as temperature unit' do @@ -106,12 +115,12 @@ response = client.lookup_by_woeid 455821 response.units['temperature'].should == 'F' - response.forecasts.first['low'].should == 63 - response.forecasts.last['low'].should == 63 - response.forecasts.first['high'].should == 75 + response.forecasts.first['low'].should == 61 + response.forecasts.last['low'].should == 57 + response.forecasts.first['high'].should == 80 response.forecasts.last['high'].should == 79 - response.condition['temp'].should == 66 - response.condition['date'].should == DateTime.parse('Sat, 18 Mar 2010 12:00 am LST') + response.condition['temp'].should == 72 + response.condition['date'].should == DateTime.parse('Sun, 22 May 2016 09:00 AM BRT') end end diff --git a/yahoo_weatherman.gemspec b/yahoo_weatherman.gemspec index 98a1a17..0b1d8e9 100644 --- a/yahoo_weatherman.gemspec +++ b/yahoo_weatherman.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "yahoo_weatherman" - gem.version = "2.0.0" + gem.version = "2.0.3" gem.authors = ["Dalto Curvelano Junior"] gem.description = "A ruby wrapper to the Yahoo! Weather feed with i18n support." gem.summary = "A ruby wrapper to the Yahoo! Weather feed with i18n support."