barometer 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +2 -5
- data/Gemfile +11 -7
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/barometer.gemspec +7 -10
- data/lib/barometer/utils/json_reader.rb +2 -3
- data/lib/barometer/utils/payload.rb +6 -87
- data/lib/barometer/utils/translations/zone_codes.yml +1 -0
- data/lib/barometer/version.rb +1 -1
- data/lib/barometer/weather_service.rb +0 -1
- data/spec/barometer_spec.rb +6 -0
- data/spec/spec_helper.rb +0 -11
- data/spec/utils/payload_spec.rb +20 -153
- data/spec/weather_services/wunderground_v1/current_response_spec.rb +5 -4
- data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +23 -22
- metadata +32 -170
- data/.pelusa.yml +0 -7
- data/lib/barometer/weather_services/weather_bug.rb +0 -41
- data/lib/barometer/weather_services/weather_bug/current_api.rb +0 -26
- data/lib/barometer/weather_services/weather_bug/current_response.rb +0 -33
- data/lib/barometer/weather_services/weather_bug/forecast_api.rb +0 -26
- data/lib/barometer/weather_services/weather_bug/forecast_response.rb +0 -29
- data/lib/barometer/weather_services/weather_bug/query.rb +0 -42
- data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +0 -82
- data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +0 -67
- data/lib/barometer/weather_services/weather_bug/response/location.rb +0 -23
- data/lib/barometer/weather_services/weather_bug/response/station.rb +0 -43
- data/lib/barometer/weather_services/weather_bug/response/sun.rb +0 -32
- data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +0 -52
- data/lib/barometer/weather_services/weather_bug/response/timezone.rb +0 -15
- data/spec/cassettes/WeatherService_WeatherBug.json +0 -1
- data/spec/weather_services/weather_bug/current_response_spec.rb +0 -64
- data/spec/weather_services/weather_bug/forecast_response_spec.rb +0 -23
- data/spec/weather_services/weather_bug/query_spec.rb +0 -44
- data/spec/weather_services/weather_bug_spec.rb +0 -80
@@ -1,52 +0,0 @@
|
|
1
|
-
module Barometer
|
2
|
-
module WeatherService
|
3
|
-
class WeatherBug
|
4
|
-
class Response
|
5
|
-
class TimeHelper
|
6
|
-
def initialize(payload, timezone)
|
7
|
-
@payload = payload
|
8
|
-
@timezone = timezone
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse(key)
|
12
|
-
return unless local_time(key)
|
13
|
-
timezone.local_to_utc(local_time(key))
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :payload, :timezone, :key
|
19
|
-
|
20
|
-
def local_time(key)
|
21
|
-
@key = key
|
22
|
-
@local_time ||= Utils::Time.parse(year, month, day, hour, minute, second)
|
23
|
-
end
|
24
|
-
|
25
|
-
def year
|
26
|
-
payload.fetch(key, 'year', '@number')
|
27
|
-
end
|
28
|
-
|
29
|
-
def month
|
30
|
-
payload.fetch(key, 'month', '@number')
|
31
|
-
end
|
32
|
-
|
33
|
-
def day
|
34
|
-
payload.fetch(key, 'day', '@number')
|
35
|
-
end
|
36
|
-
|
37
|
-
def hour
|
38
|
-
payload.fetch(key, 'hour', '@hour_24')
|
39
|
-
end
|
40
|
-
|
41
|
-
def minute
|
42
|
-
payload.fetch(key, 'minute', '@number')
|
43
|
-
end
|
44
|
-
|
45
|
-
def second
|
46
|
-
payload.fetch(key, 'second', '@number')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
{"http_interactions":[{"request":{"method":"get","uri":"http://WEATHERBUG_CODE.api.wxbug.net/getLiveWeatherRSS.aspx?ACode=WEATHERBUG_CODE&OutputType=1&UnitType=1&zipCode=90210","body":{"encoding":"UTF-8","string":""},"headers":{}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["private"],"Content-Type":["application/xml; charset=utf-8"],"Date":["Sat, 26 Oct 2013 14:55:07 GMT"],"Server":["Microsoft-IIS/7.5"],"Set-Cookie":["ASP.NET_SessionId=2q2lm10ejga21x3jdps0f0rm; path=/; HttpOnly"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["4076"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"<aws:weather xmlns:aws=\"http://www.aws.com/aws\"><aws:api version=\"2.0\" /><aws:WebURL>http://weather.weatherbug.com/CA/Valley Village-weather.html?ZCode=Z5546&Units=1&stat=NRTSH</aws:WebURL><aws:InputLocationURL>http://weather.weatherbug.com/CA/Beverly Hills-weather.html?ZCode=Z5546&Units=1</aws:InputLocationURL><aws:ob><aws:ob-date><aws:year number=\"2013\" /><aws:month number=\"10\" text=\"October\" abbrv=\"Oct\" /><aws:day number=\"26\" text=\"Saturday\" abbrv=\"Sat\" /><aws:hour number=\"7\" hour-24=\"07\" /><aws:minute number=\"54\" /><aws:second number=\"00\" /><aws:am-pm abbrv=\"AM\" /><aws:time-zone offset=\"-7\" text=\"Pacific Daylight Time (USA)\" abbrv=\"PDT\" /></aws:ob-date><aws:requested-station-id /><aws:station-id>NRTSH</aws:station-id><aws:station>Campbell Hall School</aws:station><aws:city-state zipcode=\"91617\">Valley Village, CA</aws:city-state><aws:country>USA</aws:country><aws:latitude>34.1536102294922</aws:latitude><aws:longitude>-118.398056030273</aws:longitude><aws:site-url>http://www.campbell.pvt.k12.ca.us/</aws:site-url><aws:aux-temp units=\"&deg;C\">18</aws:aux-temp><aws:aux-temp-rate units=\"&deg;C\">0.0</aws:aux-temp-rate><aws:current-condition icon=\"http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif\">Mostly Sunny</aws:current-condition><aws:dew-point units=\"&deg;C\">11</aws:dew-point><aws:elevation units=\"m\">192</aws:elevation><aws:feels-like units=\"&deg;C\">12</aws:feels-like><aws:gust-time><aws:year number=\"2013\" /><aws:month number=\"10\" text=\"October\" abbrv=\"Oct\" /><aws:day number=\"26\" text=\"Saturday\" abbrv=\"Sat\" /><aws:hour number=\"12\" hour-24=\"00\" /><aws:minute number=\"59\" /><aws:second number=\"00\" /><aws:am-pm abbrv=\"AM\" /><aws:time-zone offset=\"-7\" text=\"Pacific Daylight Time (USA)\" abbrv=\"PDT\" /></aws:gust-time><aws:gust-direction>S</aws:gust-direction><aws:gust-direction-degrees>174</aws:gust-direction-degrees><aws:gust-speed units=\"km/h\">2</aws:gust-speed><aws:humidity units=\"%\">97</aws:humidity><aws:humidity-high units=\"%\">97</aws:humidity-high><aws:humidity-low units=\"%\">89</aws:humidity-low><aws:humidity-rate>0</aws:humidity-rate><aws:indoor-temp units=\"&deg;C\">24</aws:indoor-temp><aws:indoor-temp-rate units=\"&deg;C\">0</aws:indoor-temp-rate><aws:light>0</aws:light><aws:light-rate>0</aws:light-rate><aws:moon-phase moon-phase-img=\"http://api.wxbug.net/images/moonphase/mphase19.gif\">59</aws:moon-phase><aws:pressure units=\"mb\">1017.27</aws:pressure><aws:pressure-high units=\"mb\">1017.27</aws:pressure-high><aws:pressure-low units=\"mb\">1016.60</aws:pressure-low><aws:pressure-rate units=\"mb/h\">0.68</aws:pressure-rate><aws:rain-month units=\"mm\">0.00</aws:rain-month><aws:rain-rate units=\"mm/h\">0.00</aws:rain-rate><aws:rain-rate-max units=\"mm/h\">0.00</aws:rain-rate-max><aws:rain-today units=\"mm\">0.00</aws:rain-today><aws:rain-year units=\"mm\">87.63</aws:rain-year><aws:temp units=\"&deg;C\">11.9</aws:temp><aws:temp-high units=\"&deg;C\">16</aws:temp-high><aws:temp-low units=\"&deg;C\">11</aws:temp-low><aws:temp-rate units=\"&deg;C/h\">0.6</aws:temp-rate><aws:sunrise><aws:year number=\"2013\" /><aws:month number=\"10\" text=\"October\" abbrv=\"Oct\" /><aws:day number=\"26\" text=\"Saturday\" abbrv=\"Sat\" /><aws:hour number=\"7\" hour-24=\"07\" /><aws:minute number=\"07\" /><aws:second number=\"55\" /><aws:am-pm abbrv=\"AM\" /><aws:time-zone offset=\"-7\" text=\"Pacific Daylight Time (USA)\" abbrv=\"PDT\" /></aws:sunrise><aws:sunset><aws:year number=\"2013\" /><aws:month number=\"10\" text=\"October\" abbrv=\"Oct\" /><aws:day number=\"26\" text=\"Saturday\" abbrv=\"Sat\" /><aws:hour number=\"6\" hour-24=\"18\" /><aws:minute number=\"06\" /><aws:second number=\"47\" /><aws:am-pm abbrv=\"PM\" /><aws:time-zone offset=\"-7\" text=\"Pacific Daylight Time (USA)\" abbrv=\"PDT\" /></aws:sunset><aws:wet-bulb units=\"&deg;C\">11.65</aws:wet-bulb><aws:wind-speed units=\"km/h\">0</aws:wind-speed><aws:wind-speed-avg units=\"km/h\">0</aws:wind-speed-avg><aws:wind-direction>S</aws:wind-direction><aws:wind-direction-degrees>173</aws:wind-direction-degrees><aws:wind-direction-avg>S</aws:wind-direction-avg></aws:ob></aws:weather>\r\n"},"http_version":null},"recorded_at":"Sat, 26 Oct 2013 14:55:07 GMT"},{"request":{"method":"get","uri":"http://WEATHERBUG_CODE.api.wxbug.net/getForecastRSS.aspx?ACode=WEATHERBUG_CODE&OutputType=1&UnitType=1&zipCode=90210","body":{"encoding":"UTF-8","string":""},"headers":{}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["private"],"Content-Type":["application/xml; charset=utf-8"],"Date":["Sat, 26 Oct 2013 14:55:07 GMT"],"Server":["Microsoft-IIS/7.5"],"Set-Cookie":["ASP.NET_SessionId=ppstsmui0taeaponkcny3cjz; path=/; HttpOnly"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["4096"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"<aws:weather xmlns:aws=\"http://www.aws.com/aws\"><aws:api version=\"2.0\" /><aws:WebURL>http://weather.weatherbug.com/CA/Beverly Hills-weather/local-forecast/7-day-forecast.html?ZCode=Z5546&Units=1</aws:WebURL><aws:forecasts type=\"Detailed\" date=\"10/26/2013 3:15:00 AM\"><aws:location><aws:city>Beverly Hills</aws:city><aws:state>CA</aws:state><aws:zip>90210</aws:zip><aws:zone>CA041</aws:zone></aws:location><aws:forecast><aws:title alttitle=\"SAT\">Saturday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond003.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Saturday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs from the lower to mid 70s at the beaches to around 80 inland.</aws:prediction><aws:high units=\"&deg;C\">27</aws:high><aws:low units=\"&deg;C\">15</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"SUN\">Sunday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond003.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Sunday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs from the upper 60s at the beaches to the upper 70s inland.</aws:prediction><aws:high units=\"&deg;C\">26</aws:high><aws:low units=\"&deg;C\">13</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"MON\">Monday</aws:title><aws:short-prediction>40% Chance Rain Shower</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond109.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond109.gif</aws:image><aws:description>Monday</aws:description><aws:prediction>Mostly cloudy. A slight chance of showers in the morning then a chance of showers in the afternoon. Highs in the 60s. Southeast winds around 15 mph in the afternoon. Chance of precipitation 40 percent.</aws:prediction><aws:high units=\"&deg;C\">18</aws:high><aws:low units=\"&deg;C\">11</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"TUE\">Tuesday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond003.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Tuesday</aws:description><aws:prediction>Mostly cloudy with a 20 percent chance of showers in the morning then partly cloudy in the afternoon. Highs in the lower to mid 60s.</aws:prediction><aws:high units=\"&deg;C\">17</aws:high><aws:low units=\"&deg;C\">12</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"WED\">Wednesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond026.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Wednesday</aws:description><aws:prediction>Mostly clear. Highs from the mid 60s at the beaches to the mid 70s inland. Lows in the 50s.</aws:prediction><aws:high units=\"&deg;C\">22</aws:high><aws:low units=\"&deg;C\">12</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"THU\">Thursday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond026.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Thursday</aws:description><aws:prediction>Mostly clear. Highs from the mid 60s at the beaches to the mid 70s inland. Lows in the 50s.</aws:prediction><aws:high units=\"&deg;C\">23</aws:high><aws:low units=\"&deg;C\">13</aws:low></aws:forecast><aws:forecast><aws:title alttitle=\"FRI\">Friday</aws:title><aws:short-prediction>Sunny</aws:short-prediction><aws:image isNight=\"0\" icon=\"cond007.gif\">http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif</aws:image><aws:description>Friday</aws:description><aws:prediction>Sunny. Highs from around 70 at the beaches to around 80 inland.</aws:prediction><aws:high units=\"&deg;C\">26</aws:high><aws:low units=\"&deg;C\">--</aws:low></aws:forecast></aws:forecasts></aws:weather>\r\n"},"http_version":null},"recorded_at":"Sat, 26 Oct 2013 14:55:07 GMT"}],"recorded_with":"VCR 2.6.0"}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
module Barometer::WeatherService
|
4
|
-
describe WeatherBug::CurrentResponse do
|
5
|
-
it "parses the timezones correctly" do
|
6
|
-
payload = Barometer::Utils::Payload.new({
|
7
|
-
'ob_date' => {
|
8
|
-
'year' => { '@number' => '2013' },
|
9
|
-
'month' => { '@number' => '5' },
|
10
|
-
'day' => { '@number' => '18' },
|
11
|
-
'hour' => { '@hour_24' => '10' },
|
12
|
-
'minute' => { '@number' => '46' },
|
13
|
-
'second' => { '@number' => '0' },
|
14
|
-
'time_zone' => { '@abbrv' => 'PDT' }
|
15
|
-
}
|
16
|
-
})
|
17
|
-
response = WeatherBug::CurrentResponse.new.parse(payload)
|
18
|
-
|
19
|
-
utc_observed_at = Time.utc(2013,5,18,17,46,0)
|
20
|
-
utc_stale_at = Time.utc(2013,5,18,18,46,0)
|
21
|
-
|
22
|
-
expect( response.current.observed_at.utc ).to eq utc_observed_at
|
23
|
-
expect( response.current.stale_at.utc ).to eq utc_stale_at
|
24
|
-
expect( response.timezone.to_s ).to eq 'PDT'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "parses sun timezones correctly" do
|
28
|
-
payload = Barometer::Utils::Payload.new({
|
29
|
-
'ob_date' => {
|
30
|
-
'year' => { '@number' => '2013' },
|
31
|
-
'month' => { '@number' => '4' },
|
32
|
-
'day' => { '@number' => '13' },
|
33
|
-
'hour' => { '@hour_24' => '10' },
|
34
|
-
'minute' => { '@number' => '23' },
|
35
|
-
'second' => { '@number' => '0' },
|
36
|
-
'time_zone' => { '@abbrv' => 'PDT' }
|
37
|
-
},
|
38
|
-
'sunrise' => {
|
39
|
-
'year' => { '@number' => '2013' },
|
40
|
-
'month' => { '@number' => '4' },
|
41
|
-
'day' => { '@number' => '13' },
|
42
|
-
'hour' => { '@hour_24' => '6' },
|
43
|
-
'minute' => { '@number' => '44' },
|
44
|
-
'second' => { '@number' => '19' },
|
45
|
-
},
|
46
|
-
'sunset' => {
|
47
|
-
'year' => { '@number' => '2013' },
|
48
|
-
'month' => { '@number' => '4' },
|
49
|
-
'day' => { '@number' => '13' },
|
50
|
-
'hour' => { '@hour_24' => '17' },
|
51
|
-
'minute' => { '@number' => '31' },
|
52
|
-
'second' => { '@number' => '50' },
|
53
|
-
}
|
54
|
-
})
|
55
|
-
response = WeatherBug::CurrentResponse.new.parse(payload)
|
56
|
-
|
57
|
-
utc_current_sun_rise = Time.utc(2013,4,13,13,44,19)
|
58
|
-
utc_current_sun_set = Time.utc(2013,4,14,0,31,50)
|
59
|
-
|
60
|
-
expect( response.current.sun.rise.utc ).to eq utc_current_sun_rise
|
61
|
-
expect( response.current.sun.set.utc ).to eq utc_current_sun_set
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
module Barometer::WeatherService
|
4
|
-
describe WeatherBug::ForecastResponse do
|
5
|
-
let(:current_response) { Barometer::Response.new }
|
6
|
-
|
7
|
-
it "parses the timezones correctly" do
|
8
|
-
current_response.timezone = Barometer::Data::Zone.new('PDT')
|
9
|
-
|
10
|
-
payload = Barometer::Utils::Payload.new({
|
11
|
-
"@date" => "4/13/2013 10:23:00 AM",
|
12
|
-
"forecast" => [{"high" => "13"}]
|
13
|
-
})
|
14
|
-
response = WeatherBug::ForecastResponse.new(current_response).parse(payload)
|
15
|
-
|
16
|
-
utc_starts_at = Time.utc(2013,4,13,7,0,0)
|
17
|
-
utc_ends_at = Time.utc(2013,4,14,6,59,59)
|
18
|
-
|
19
|
-
expect( response.forecast[0].starts_at.utc ).to eq utc_starts_at
|
20
|
-
expect( response.forecast[0].ends_at.utc ).to eq utc_ends_at
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
module Barometer::WeatherService
|
4
|
-
describe WeatherBug::Query do
|
5
|
-
describe '#to_param' do
|
6
|
-
let(:converted_query) { double(:converted_query).as_null_object }
|
7
|
-
let(:query) { WeatherBug::Query.new(converted_query) }
|
8
|
-
|
9
|
-
context 'when the query is a :short_zipcode' do
|
10
|
-
before { converted_query.stub(format: :short_zipcode, q: '90210') }
|
11
|
-
|
12
|
-
it 'includes the correct parameters' do
|
13
|
-
expect( query.to_param[:zipCode] ).to eq '90210'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'and the query is a :coordinates' do
|
18
|
-
let(:geo) { double(:geo, latitude: '11.22', longitude: '33.44') }
|
19
|
-
before { converted_query.stub(format: :coordinates, geo: geo) }
|
20
|
-
|
21
|
-
it 'includes the correct parameters' do
|
22
|
-
expect( query.to_param[:lat] ).to eq '11.22'
|
23
|
-
expect( query.to_param[:long] ).to eq '33.44'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'and the query is metric' do
|
28
|
-
before { converted_query.stub(metric?: true) }
|
29
|
-
|
30
|
-
it 'includes the correct parameters' do
|
31
|
-
expect( query.to_param[:UnitType] ).to eq '1'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'and the query is imperial' do
|
36
|
-
before { converted_query.stub(metric?: false) }
|
37
|
-
|
38
|
-
it 'includes the correct parameters' do
|
39
|
-
expect( query.to_param[:UnitType] ).to eq '0'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
module Barometer
|
4
|
-
describe WeatherService::WeatherBug, vcr: {
|
5
|
-
cassette_name: 'WeatherService::WeatherBug'
|
6
|
-
} do
|
7
|
-
|
8
|
-
it 'auto-registers this weather service as :weather_bug' do
|
9
|
-
expect( WeatherService.source(:weather_bug) ).to eq WeatherService::WeatherBug
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.call' do
|
13
|
-
context 'when no keys are provided' do
|
14
|
-
let(:query) { build_query }
|
15
|
-
|
16
|
-
it 'raises an error' do
|
17
|
-
expect {
|
18
|
-
WeatherService::WeatherBug.call(query)
|
19
|
-
}.to raise_error(WeatherService::KeyRequired)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when keys are provided' do
|
24
|
-
let(:converted_query) { Barometer::ConvertedQuery.new('90210', :short_zipcode, :metric) }
|
25
|
-
let(:query) { build_query.tap{|q|q.stub(:convert! => converted_query)} }
|
26
|
-
let(:config) { {keys: {code: WEATHERBUG_CODE}} }
|
27
|
-
|
28
|
-
subject { WeatherService::WeatherBug.call(query, config) }
|
29
|
-
|
30
|
-
it 'converts the query to accepted formats' do
|
31
|
-
subject
|
32
|
-
expect( query ).to have_received(:convert!).with(:short_zipcode, :coordinates).at_least(:once)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'includes the expected data' do
|
36
|
-
expect( subject.query ).to eq '90210'
|
37
|
-
expect( subject.format ).to eq :short_zipcode
|
38
|
-
expect( subject ).to be_metric
|
39
|
-
|
40
|
-
should have_data(:current, :observed_at).as_format(:time)
|
41
|
-
should have_data(:current, :stale_at).as_format(:time)
|
42
|
-
|
43
|
-
should have_data(:current, :humidity).as_format(:float)
|
44
|
-
should have_data(:current, :condition).as_format(:string)
|
45
|
-
should have_data(:current, :icon).as_format(:number)
|
46
|
-
should have_data(:current, :temperature).as_format(:temperature)
|
47
|
-
should have_data(:current, :dew_point).as_format(:temperature)
|
48
|
-
should have_data(:current, :wind_chill).as_format(:temperature)
|
49
|
-
should have_data(:current, :wind).as_format(:vector)
|
50
|
-
should have_data(:current, :pressure).as_format(:pressure)
|
51
|
-
should have_data(:current, :sun, :rise).as_format(:time)
|
52
|
-
should have_data(:current, :sun, :set).as_format(:time)
|
53
|
-
|
54
|
-
should have_data(:station, :id).as_value('NRTSH')
|
55
|
-
should have_data(:station, :name).as_value('Campbell Hall School')
|
56
|
-
should have_data(:station, :city).as_value('Valley Village')
|
57
|
-
should have_data(:station, :state_code).as_value('CA')
|
58
|
-
should have_data(:station, :country).as_value('USA')
|
59
|
-
should have_data(:station, :zip_code).as_value('91617')
|
60
|
-
should have_data(:station, :latitude).as_value(34.1536102294922)
|
61
|
-
should have_data(:station, :longitude).as_value(-118.398056030273)
|
62
|
-
|
63
|
-
should have_data(:location, :city).as_value('Beverly Hills')
|
64
|
-
should have_data(:location, :state_code).as_value('CA')
|
65
|
-
should have_data(:location, :zip_code).as_value('90210')
|
66
|
-
|
67
|
-
should have_data(:timezone, :to_s).as_format(/^P[DS]T$/i)
|
68
|
-
|
69
|
-
expect( subject.forecast.size ).to eq 7
|
70
|
-
should have_forecast(:starts_at).as_format(:time)
|
71
|
-
should have_forecast(:ends_at).as_format(:time)
|
72
|
-
should have_forecast(:condition).as_format(:string)
|
73
|
-
should have_forecast(:icon).as_format(:number)
|
74
|
-
should have_forecast(:high).as_format(:temperature)
|
75
|
-
should have_forecast(:low).as_format(:temperature)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|