barometer-weather_bug 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/barometer/weather_bug.rb +16 -7
- data/lib/barometer/weather_bug/current_api.rb +10 -6
- data/lib/barometer/weather_bug/current_response.rb +1 -11
- data/lib/barometer/weather_bug/forecast_api.rb +10 -6
- data/lib/barometer/weather_bug/forecast_response.rb +1 -8
- data/lib/barometer/weather_bug/oauth_api.rb +28 -0
- data/lib/barometer/weather_bug/oauth_token.rb +32 -0
- data/lib/barometer/weather_bug/query.rb +17 -9
- data/lib/barometer/weather_bug/response/current_weather.rb +7 -32
- data/lib/barometer/weather_bug/response/forecasted_weather.rb +29 -15
- data/lib/barometer/weather_bug/version.rb +1 -1
- data/spec/cassettes/WeatherBug.json +1 -0
- data/spec/spec_helper.rb +10 -6
- data/spec/weather_bug/current_response_spec.rb +3 -51
- data/spec/weather_bug/forecast_response_spec.rb +7 -8
- data/spec/weather_bug/query_spec.rb +4 -12
- data/spec/weather_bug_spec.rb +53 -48
- metadata +5 -8
- data/lib/barometer/weather_bug/response/location.rb +0 -21
- data/lib/barometer/weather_bug/response/station.rb +0 -41
- data/lib/barometer/weather_bug/response/sun.rb +0 -30
- data/lib/barometer/weather_bug/response/time_helper.rb +0 -50
- data/lib/barometer/weather_bug/response/timezone.rb +0 -13
- data/spec/cassettes/WeatherService_WeatherBug.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f5f4643fbfdd655e3315a979a3e28f92f225def
|
4
|
+
data.tar.gz: bb99772cb88028ab94b5c3498290ab6110c45fbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f7672fa16440e190c9abf9efc3107aaef15f57293de1012ace92bd4e42b963ad51ca45c491136658645d55b8bb9f0c4874e5d16e971fef43cf5e9c6889b140
|
7
|
+
data.tar.gz: 05614917e35afeedfb5d2e6f7b458f9c2d4f4e3f70ad60494e75db485e02e321512476642739c50443709231e5f987790c8e1169f73a948a5f85c2dada54feff
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ processing.
|
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
query = Barometer::Query.new('42.7243,-73.6927')
|
23
|
-
keys = {
|
23
|
+
keys = {client_id: 'client_id', client_secret: 'client_secret'}
|
24
24
|
|
25
25
|
result = Barometer::WeatherBug.call(query, keys: keys)
|
26
26
|
puts result.current.temperature.c
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'barometer'
|
2
2
|
require_relative 'weather_bug/version'
|
3
|
+
require_relative 'weather_bug/oauth_api'
|
4
|
+
require_relative 'weather_bug/oauth_token'
|
3
5
|
require_relative 'weather_bug/current_api'
|
4
6
|
require_relative 'weather_bug/current_response'
|
5
7
|
require_relative 'weather_bug/forecast_api'
|
@@ -13,25 +15,32 @@ module Barometer
|
|
13
15
|
|
14
16
|
def initialize(query, config={})
|
15
17
|
@query = query
|
16
|
-
|
18
|
+
|
19
|
+
if config.has_key? :keys
|
20
|
+
@api_client_id = config[:keys][:client_id]
|
21
|
+
@api_client_secret = config[:keys][:client_secret]
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
def measure!
|
20
|
-
|
26
|
+
validate_keys!
|
27
|
+
|
28
|
+
oauth_token_api = OauthApi.new(api_client_id, api_client_secret)
|
29
|
+
oauth_token = OauthToken.new(oauth_token_api)
|
21
30
|
|
22
|
-
current_weather_api = CurrentApi.new(query,
|
31
|
+
current_weather_api = CurrentApi.new(query, oauth_token)
|
23
32
|
response = CurrentResponse.new.parse(current_weather_api.get)
|
24
33
|
|
25
|
-
forecast_weather_api = ForecastApi.new(current_weather_api.query,
|
34
|
+
forecast_weather_api = ForecastApi.new(current_weather_api.query, oauth_token)
|
26
35
|
ForecastResponse.new(response).parse(forecast_weather_api.get)
|
27
36
|
end
|
28
37
|
|
29
38
|
private
|
30
39
|
|
31
|
-
attr_reader :query, :
|
40
|
+
attr_reader :query, :api_client_id, :api_client_secret
|
32
41
|
|
33
|
-
def
|
34
|
-
unless
|
42
|
+
def validate_keys!
|
43
|
+
unless api_client_id && api_client_secret
|
35
44
|
raise Barometer::WeatherService::KeyRequired
|
36
45
|
end
|
37
46
|
end
|
@@ -3,21 +3,25 @@ require_relative 'query'
|
|
3
3
|
module Barometer
|
4
4
|
class WeatherBug
|
5
5
|
class CurrentApi < Utils::Api
|
6
|
-
def initialize(query,
|
6
|
+
def initialize(query, oauth_token)
|
7
7
|
@query = WeatherBug::Query.new(query)
|
8
|
-
@
|
8
|
+
@oauth_token = oauth_token
|
9
9
|
end
|
10
10
|
|
11
11
|
def url
|
12
|
-
|
12
|
+
'https://thepulseapi.earthnetworks.com/data/observations/v1/current'
|
13
13
|
end
|
14
14
|
|
15
15
|
def params
|
16
|
-
|
16
|
+
oauth2_params.merge(@query.to_param)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :oauth_token
|
22
|
+
|
23
|
+
def oauth2_params
|
24
|
+
{ access_token: oauth_token.access_token }
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require_relative 'response/timezone'
|
2
1
|
require_relative 'response/current_weather'
|
3
|
-
require_relative 'response/station'
|
4
2
|
|
5
3
|
module Barometer
|
6
4
|
class WeatherBug
|
@@ -11,21 +9,13 @@ module Barometer
|
|
11
9
|
|
12
10
|
def parse(payload)
|
13
11
|
response.add_query(payload.query)
|
14
|
-
|
15
|
-
response.timezone = WeatherBug::Response::TimeZone.new(payload).parse
|
16
|
-
response.current = WeatherBug::Response::CurrentWeather.new(payload, timezone).parse
|
17
|
-
response.station = WeatherBug::Response::Station.new(payload).parse
|
18
|
-
|
12
|
+
response.current = WeatherBug::Response::CurrentWeather.new(payload).parse
|
19
13
|
response
|
20
14
|
end
|
21
15
|
|
22
16
|
private
|
23
17
|
|
24
18
|
attr_reader :response
|
25
|
-
|
26
|
-
def timezone
|
27
|
-
response.timezone
|
28
|
-
end
|
29
19
|
end
|
30
20
|
end
|
31
21
|
end
|
@@ -3,21 +3,25 @@ require_relative 'query'
|
|
3
3
|
module Barometer
|
4
4
|
class WeatherBug
|
5
5
|
class ForecastApi < Utils::Api
|
6
|
-
def initialize(query,
|
6
|
+
def initialize(query, oauth_token)
|
7
7
|
@query = WeatherBug::Query.new(query)
|
8
|
-
@
|
8
|
+
@oauth_token = oauth_token
|
9
9
|
end
|
10
10
|
|
11
11
|
def url
|
12
|
-
|
12
|
+
'https://thepulseapi.earthnetworks.com/data/forecasts/v1/daily'
|
13
13
|
end
|
14
14
|
|
15
15
|
def params
|
16
|
-
|
16
|
+
oauth2_params.merge(@query.to_param)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :oauth_token
|
22
|
+
|
23
|
+
def oauth2_params
|
24
|
+
{ access_token: oauth_token.access_token }
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative 'response/forecasted_weather'
|
2
|
-
require_relative 'response/location'
|
3
2
|
|
4
3
|
module Barometer
|
5
4
|
class WeatherBug
|
@@ -9,19 +8,13 @@ module Barometer
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def parse(payload)
|
12
|
-
response.forecast = WeatherBug::Response::ForecastedWeather.new(payload
|
13
|
-
response.location = WeatherBug::Response::Location.new(payload).parse
|
14
|
-
|
11
|
+
response.forecast = WeatherBug::Response::ForecastedWeather.new(payload).parse
|
15
12
|
response
|
16
13
|
end
|
17
14
|
|
18
15
|
private
|
19
16
|
|
20
17
|
attr_reader :response
|
21
|
-
|
22
|
-
def timezone
|
23
|
-
response.timezone
|
24
|
-
end
|
25
18
|
end
|
26
19
|
end
|
27
20
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'query'
|
2
|
+
|
3
|
+
module Barometer
|
4
|
+
class WeatherBug
|
5
|
+
class OauthApi < Utils::Api
|
6
|
+
def initialize(api_client_id, api_client_secret)
|
7
|
+
@api_client_id = api_client_id
|
8
|
+
@api_client_secret = api_client_secret
|
9
|
+
end
|
10
|
+
|
11
|
+
def url
|
12
|
+
'https://thepulseapi.earthnetworks.com/oauth20/token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
{
|
17
|
+
grant_type: 'client_credentials',
|
18
|
+
client_id: @api_client_id,
|
19
|
+
client_secret: @api_client_secret
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def unwrap_nodes
|
24
|
+
['OAuth20', 'access_token']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative 'query'
|
3
|
+
|
4
|
+
module Barometer
|
5
|
+
class WeatherBug
|
6
|
+
class OauthToken
|
7
|
+
def initialize(oauth_token_api)
|
8
|
+
@oauth_token_api = oauth_token_api
|
9
|
+
@access_token = nil
|
10
|
+
@expires_at = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def access_token
|
14
|
+
refresh_token if stale_token?
|
15
|
+
@access_token
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def stale_token?
|
21
|
+
@access_token == nil || @expires_at == nil ||
|
22
|
+
@expires_at < Time.now.utc
|
23
|
+
end
|
24
|
+
|
25
|
+
def refresh_token
|
26
|
+
response = @oauth_token_api.get
|
27
|
+
@access_token = response.fetch(:token)
|
28
|
+
@expires_at = Time.now.utc + response.fetch(:expires_in)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,7 +6,7 @@ module Barometer
|
|
6
6
|
attr_reader :converted_query
|
7
7
|
|
8
8
|
def self.accepted_formats
|
9
|
-
[:
|
9
|
+
[:coordinates]
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(query)
|
@@ -15,7 +15,11 @@ module Barometer
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_param
|
18
|
-
{
|
18
|
+
{
|
19
|
+
locationtype: location_type,
|
20
|
+
units: units,
|
21
|
+
verbose: 'true'
|
22
|
+
}.merge(format_query)
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
@@ -24,17 +28,21 @@ module Barometer
|
|
24
28
|
convert!(*self.class.accepted_formats)
|
25
29
|
end
|
26
30
|
|
31
|
+
def location_type
|
32
|
+
'latitudelongitude'
|
33
|
+
end
|
34
|
+
|
35
|
+
def units
|
36
|
+
converted_query.metric? ? 'metric' : 'english'
|
37
|
+
end
|
38
|
+
|
27
39
|
def format_query
|
28
|
-
if converted_query.
|
29
|
-
{
|
40
|
+
if converted_query.geo
|
41
|
+
{ location: "#{converted_query.geo.latitude},#{converted_query.geo.longitude}" }
|
30
42
|
else
|
31
|
-
{
|
43
|
+
{ location: converted_query.to_s }
|
32
44
|
end
|
33
45
|
end
|
34
|
-
|
35
|
-
def unit_type
|
36
|
-
converted_query.metric? ? '1' : '0'
|
37
|
-
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
@@ -1,78 +1,53 @@
|
|
1
|
-
require_relative 'time_helper'
|
2
|
-
require_relative 'sun'
|
3
|
-
|
4
1
|
module Barometer
|
5
2
|
class WeatherBug
|
6
3
|
class Response
|
7
4
|
class CurrentWeather
|
8
|
-
def initialize(payload
|
5
|
+
def initialize(payload)
|
9
6
|
@payload = payload
|
10
|
-
@timezone = timezone
|
11
7
|
@current = Barometer::Response::Current.new
|
12
8
|
end
|
13
9
|
|
14
10
|
def parse
|
15
11
|
current.observed_at = observed_at
|
16
|
-
current.stale_at = stale_at
|
17
12
|
current.humidity = humidity
|
18
|
-
current.condition = condition
|
19
13
|
current.icon = icon
|
20
14
|
current.temperature = temperature
|
21
15
|
current.dew_point = dew_point
|
22
|
-
current.wind_chill = wind_chill
|
23
16
|
current.wind = wind
|
24
|
-
current.pressure = pressure
|
25
|
-
current.sun = WeatherBug::Response::Sun.new(payload, timezone).parse
|
26
17
|
|
27
18
|
current
|
28
19
|
end
|
29
20
|
|
30
21
|
private
|
31
22
|
|
32
|
-
attr_reader :payload, :
|
23
|
+
attr_reader :payload, :current
|
33
24
|
|
34
25
|
def units
|
35
26
|
payload.units
|
36
27
|
end
|
37
28
|
|
38
29
|
def observed_at
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def stale_at
|
43
|
-
Utils::Time.add_one_hour(observed_at)
|
30
|
+
Utils::Time.parse(payload.fetch('observationTimeUtcStr'), '%Y-%m-%dT%H:%M:%S')
|
44
31
|
end
|
45
32
|
|
46
33
|
def humidity
|
47
34
|
payload.fetch('humidity')
|
48
35
|
end
|
49
36
|
|
50
|
-
def condition
|
51
|
-
payload.fetch('current_condition')
|
52
|
-
end
|
53
|
-
|
54
37
|
def icon
|
55
|
-
payload.
|
38
|
+
payload.fetch('iconCode')
|
56
39
|
end
|
57
40
|
|
58
41
|
def temperature
|
59
|
-
[units, payload.fetch('
|
42
|
+
[units, payload.fetch('temperature')]
|
60
43
|
end
|
61
44
|
|
62
45
|
def dew_point
|
63
|
-
[units, payload.fetch('
|
64
|
-
end
|
65
|
-
|
66
|
-
def wind_chill
|
67
|
-
[units, payload.fetch('feels_like')]
|
46
|
+
[units, payload.fetch('dewPoint')]
|
68
47
|
end
|
69
48
|
|
70
49
|
def wind
|
71
|
-
[units, payload.fetch('
|
72
|
-
end
|
73
|
-
|
74
|
-
def pressure
|
75
|
-
[units, payload.fetch('pressure')]
|
50
|
+
[units, payload.fetch('windSpeed'), payload.fetch('windDirection')]
|
76
51
|
end
|
77
52
|
end
|
78
53
|
end
|
@@ -2,19 +2,24 @@ module Barometer
|
|
2
2
|
class WeatherBug
|
3
3
|
class Response
|
4
4
|
class ForecastedWeather
|
5
|
-
def initialize(payload
|
5
|
+
def initialize(payload)
|
6
6
|
@payload = payload
|
7
|
-
@timezone = timezone
|
8
7
|
@predictions = Barometer::Response::PredictionCollection.new
|
9
8
|
end
|
10
9
|
|
11
10
|
def parse
|
12
11
|
each_prediction do |prediction, forecast_payload, index|
|
13
|
-
prediction.
|
12
|
+
prediction.starts_at = starts_at(forecast_payload)
|
13
|
+
prediction.ends_at = ends_at(prediction.starts_at)
|
14
14
|
prediction.condition = condition(forecast_payload)
|
15
15
|
prediction.icon = icon(forecast_payload)
|
16
|
-
prediction.
|
17
|
-
|
16
|
+
prediction.pop = pop(forecast_payload)
|
17
|
+
|
18
|
+
if is_day?(forecast_payload)
|
19
|
+
prediction.high = high(forecast_payload)
|
20
|
+
else
|
21
|
+
prediction.low = low(forecast_payload)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
predictions
|
@@ -22,42 +27,51 @@ module Barometer
|
|
22
27
|
|
23
28
|
private
|
24
29
|
|
25
|
-
attr_reader :payload, :
|
30
|
+
attr_reader :payload, :predictions
|
26
31
|
|
27
32
|
def units
|
28
33
|
payload.units
|
29
34
|
end
|
30
35
|
|
31
36
|
def each_prediction
|
32
|
-
payload.fetch_each_with_index('
|
37
|
+
payload.fetch_each_with_index('dailyForecastPeriods') do |forecast_payload, index|
|
33
38
|
predictions.build do |prediction|
|
34
39
|
yield prediction, forecast_payload, index
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
|
-
def
|
40
|
-
|
44
|
+
def starts_at(forecast_payload)
|
45
|
+
Utils::Time.parse(forecast_payload.fetch('forecastDateUtcStr'), '%Y-%m-%dT%H:%M:%S%z')
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
44
|
-
|
48
|
+
def ends_at(starts_at)
|
49
|
+
half_a_day_minus_one_second = (12 * 60 * 60 - 1)
|
50
|
+
starts_at + half_a_day_minus_one_second
|
45
51
|
end
|
46
52
|
|
47
53
|
def condition(forecast_payload)
|
48
|
-
forecast_payload.fetch('
|
54
|
+
forecast_payload.fetch('summaryDescription')
|
49
55
|
end
|
50
56
|
|
51
57
|
def icon(forecast_payload)
|
52
|
-
forecast_payload.
|
58
|
+
forecast_payload.fetch('iconCode')
|
53
59
|
end
|
54
60
|
|
55
61
|
def high(forecast_payload)
|
56
|
-
[units, forecast_payload.fetch('
|
62
|
+
[units, forecast_payload.fetch('temperature')]
|
57
63
|
end
|
58
64
|
|
59
65
|
def low(forecast_payload)
|
60
|
-
[units, forecast_payload.fetch('
|
66
|
+
[units, forecast_payload.fetch('temperature')]
|
67
|
+
end
|
68
|
+
|
69
|
+
def pop(forecast_payload)
|
70
|
+
forecast_payload.fetch('precipProbability')
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_day?(forecast_payload)
|
74
|
+
!forecast_payload.fetch('isNightTimePeriod')
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"http_interactions":[{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/oauth20/token?client_id=WEATHERBUG_CLIENT_ID&client_secret=WEATHERBUG_CLIENT_SECRET&grant_type=client_credentials","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:29 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Content-Length":["157"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\"OAuth20\":{\"access_token\":{\"token\":\"WEATHERBUG_ACCESS_CODE\",\"refresh_token\":\"WEATHERBUG_ACCESS_CODE\",\"token_type\":\"bearer\",\"expires_in\":86399}}}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:30 GMT"},{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/data/observations/v1/current?access_token=WEATHERBUG_ACCESS_CODE&location=39.1,77.1&locationtype=latitudelongitude&units=metric&verbose=true","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:30 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["no-cache"],"Content-Type":["application/json; charset=utf-8"],"Date":["Sun, 13 Apr 2014 22:12:29 GMT"],"Expires":["-1"],"Pragma":["no-cache"],"Server":["Microsoft-IIS/7.5"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["1155"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\r\n \"key\": null,\r\n \"stationId\": null,\r\n \"providerId\": null,\r\n \"observationTimeLocalStr\": \"2014-04-14T05:00:00\",\r\n \"observationTimeUtcStr\": \"2014-04-13T21:00:00\",\r\n \"iconCode\": 2,\r\n \"altimeter\": null,\r\n \"altimeterRate\": null,\r\n \"dewPoint\": -10.3,\r\n \"dewPointRate\": null,\r\n \"heatIndex\": null,\r\n \"humidity\": 20.0,\r\n \"humidityRate\": null,\r\n \"pressureSeaLevel\": null,\r\n \"pressureSeaLevelRate\": null,\r\n \"rainDaily\": null,\r\n \"rainRate\": 0.0,\r\n \"rainMonthly\": null,\r\n \"rainYearly\": null,\r\n \"snowDaily\": null,\r\n \"snowRate\": null,\r\n \"snowMonthly\": null,\r\n \"snowYearly\": null,\r\n \"temperature\": 11.8,\r\n \"temperatureRate\": null,\r\n \"visibility\": null,\r\n \"visibilityRate\": null,\r\n \"windChill\": null,\r\n \"windSpeed\": 14.4,\r\n \"windDirection\": 290,\r\n \"windSpeedAvg\": null,\r\n \"windDirectionAvg\": null,\r\n \"windGustHourly\": null,\r\n \"windGustTimeLocalHourlyStr\": null,\r\n \"windGustTimeUtcHourlyStr\": null,\r\n \"windGustDirectionHourly\": null,\r\n \"windGustDaily\": null,\r\n \"windGustTimeLocalDailyStr\": null,\r\n \"windGustTimeUtcDailyStr\": null,\r\n \"windGustDirectionDaily\": null,\r\n \"observationTimeAdjustedLocalStr\": null,\r\n \"feelsLike\": 11.8\r\n}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:31 GMT"},{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/data/forecasts/v1/daily?access_token=WEATHERBUG_ACCESS_CODE&location=39.1,77.1&locationtype=latitudelongitude&units=metric&verbose=true","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:31 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["no-cache"],"Content-Type":["application/json; charset=utf-8"],"Date":["Sun, 13 Apr 2014 22:12:30 GMT"],"Expires":["-1"],"Pragma":["no-cache"],"Server":["Microsoft-IIS/7.5"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["12087"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\r\n \"dailyForecastPeriods\": [\r\n {\r\n \"cloudCoverPercent\": 37,\r\n \"dewPoint\": -15.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 13,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 20.8,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 285,\r\n \"windSpeed\": 18.0,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 21C. Dew point will be around -15C with an average humidity of 13%. Winds will be 18 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-14T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-13T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 20,\r\n \"dewPoint\": -24.0,\r\n \"iconCode\": 70,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 6,\r\n \"summaryDescription\": \"Mostly Clear\",\r\n \"temperature\": 8.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 292,\r\n \"windSpeed\": 18.0,\r\n \"detailedDescription\": \"Mostly clear. Low temperature around 8C. Dew point will be around -24C with an average humidity of 6%. Winds will be 18 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-14T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-14T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 21,\r\n \"dewPoint\": -24.0,\r\n \"iconCode\": 26,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 5,\r\n \"summaryDescription\": \"Mostly Sunny\",\r\n \"temperature\": 22.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 273,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Mostly sunny. High temperature around 22C. Dew point will be around -24C with an average humidity of 5%. Winds will be 11 kph from the W.\",\r\n \"forecastDateLocalStr\": \"2014-04-15T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-14T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 42,\r\n \"dewPoint\": -22.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 6,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 7.4,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 282,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 7C. Dew point will be around -22C with an average humidity of 6%. Winds will be 7 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-15T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-15T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 55,\r\n \"dewPoint\": -21.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 7,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 23.5,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 304,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 24C. Dew point will be around -21C with an average humidity of 7%. Winds will be 7 kph from the NW.\",\r\n \"forecastDateLocalStr\": \"2014-04-16T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-15T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 49,\r\n \"dewPoint\": -19.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 9,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 7.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 6,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 7C. Dew point will be around -19C with an average humidity of 9%. Winds will be 7 kph from the N.\",\r\n \"forecastDateLocalStr\": \"2014-04-16T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-16T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 71,\r\n \"dewPoint\": -16.0,\r\n \"iconCode\": 24,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 12,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 21.3,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 50,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Mostly cloudy. High temperature around 21C. Dew point will be around -16C with an average humidity of 12%. Winds will be 7 kph from the NE.\",\r\n \"forecastDateLocalStr\": \"2014-04-17T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-16T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 99,\r\n \"dewPoint\": -15.0,\r\n \"iconCode\": 13,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 11,\r\n \"summaryDescription\": \"Cloudy\",\r\n \"temperature\": 10.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 78,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Cloudy. Low temperature around 11C. Dew point will be around -15C with an average humidity of 11%. Winds will be 7 kph from the ENE.\",\r\n \"forecastDateLocalStr\": \"2014-04-17T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-17T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 69,\r\n \"dewPoint\": -11.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 14,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 22.0,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 44,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 22C. Dew point will be around -11C with an average humidity of 14%. Winds will be 11 kph from the NE.\",\r\n \"forecastDateLocalStr\": \"2014-04-18T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-17T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 78,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 19,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 10.9,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 82,\r\n \"windSpeed\": 14.4,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 11C. Dew point will be around -8C with an average humidity of 19%. Winds will be 14 kph from the E.\",\r\n \"forecastDateLocalStr\": \"2014-04-18T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-18T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 100,\r\n \"dewPoint\": -10.0,\r\n \"iconCode\": 1,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 17,\r\n \"summaryDescription\": \"Cloudy\",\r\n \"temperature\": 20.1,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 98,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Cloudy. High temperature around 20C. Dew point will be around -10C with an average humidity of 17%. Winds will be 7 kph from the E.\",\r\n \"forecastDateLocalStr\": \"2014-04-19T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-18T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 73,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 20,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 8.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 141,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 8C. Dew point will be around -8C with an average humidity of 20%. Winds will be 7 kph from the SE.\",\r\n \"forecastDateLocalStr\": \"2014-04-19T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-19T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 31,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 21,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 22.9,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 152,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 23C. Dew point will be around -8C with an average humidity of 21%. Winds will be 7 kph from the SSE.\",\r\n \"forecastDateLocalStr\": \"2014-04-20T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-19T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 21,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 70,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 18,\r\n \"summaryDescription\": \"Mostly Clear\",\r\n \"temperature\": 9.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 221,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly clear. Low temperature around 10C. Dew point will be around -8C with an average humidity of 18%. Winds will be 4 kph from the SW.\",\r\n \"forecastDateLocalStr\": \"2014-04-20T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-20T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 13,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 26,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 18,\r\n \"summaryDescription\": \"Mostly Sunny\",\r\n \"temperature\": 25.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 243,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly sunny. High temperature around 26C. Dew point will be around -8C with an average humidity of 18%. Winds will be 4 kph from the WSW.\",\r\n \"forecastDateLocalStr\": \"2014-04-21T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-20T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 87,\r\n \"dewPoint\": -9.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 15,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 11.1,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 72,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 11C. Dew point will be around -9C with an average humidity of 15%. Winds will be 4 kph from the ENE.\",\r\n \"forecastDateLocalStr\": \"2014-04-21T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-21T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 52,\r\n \"dewPoint\": -10.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 14,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 27.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 223,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 27C. Dew point will be around -10C with an average humidity of 14%. Winds will be 4 kph from the SW.\",\r\n \"forecastDateLocalStr\": \"2014-04-22T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-21T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 36,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 15,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 14.5,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 275,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 15C. Dew point will be around -8C with an average humidity of 15%. Winds will be 11 kph from the W.\",\r\n \"forecastDateLocalStr\": \"2014-04-22T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-22T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n }\r\n ],\r\n \"forecastCreatedUtcStr\": \"2014-04-13T12:01:00.0000000Z\",\r\n \"location\": \"CH13B0005\",\r\n \"locationType\": \"city\"\r\n}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:31 GMT"},{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/oauth20/token?client_id=WEATHERBUG_CLIENT_ID&client_secret=WEATHERBUG_CLIENT_SECRET&grant_type=client_credentials","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:31 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Content-Length":["157"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\"OAuth20\":{\"access_token\":{\"token\":\"KucXobMIyGIMjN8L0kJ4bpPg5GaV\",\"refresh_token\":\"KucXobMIyGIMjN8L0kJ4bpPg5GaV\",\"token_type\":\"bearer\",\"expires_in\":86399}}}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:32 GMT"},{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/data/observations/v1/current?access_token=KucXobMIyGIMjN8L0kJ4bpPg5GaV&location=39.1,77.1&locationtype=latitudelongitude&units=metric&verbose=true","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:32 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["no-cache"],"Content-Type":["application/json; charset=utf-8"],"Date":["Sun, 13 Apr 2014 22:12:32 GMT"],"Expires":["-1"],"Pragma":["no-cache"],"Server":["Microsoft-IIS/7.5"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["1155"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\r\n \"key\": null,\r\n \"stationId\": null,\r\n \"providerId\": null,\r\n \"observationTimeLocalStr\": \"2014-04-14T05:00:00\",\r\n \"observationTimeUtcStr\": \"2014-04-13T21:00:00\",\r\n \"iconCode\": 2,\r\n \"altimeter\": null,\r\n \"altimeterRate\": null,\r\n \"dewPoint\": -10.3,\r\n \"dewPointRate\": null,\r\n \"heatIndex\": null,\r\n \"humidity\": 20.0,\r\n \"humidityRate\": null,\r\n \"pressureSeaLevel\": null,\r\n \"pressureSeaLevelRate\": null,\r\n \"rainDaily\": null,\r\n \"rainRate\": 0.0,\r\n \"rainMonthly\": null,\r\n \"rainYearly\": null,\r\n \"snowDaily\": null,\r\n \"snowRate\": null,\r\n \"snowMonthly\": null,\r\n \"snowYearly\": null,\r\n \"temperature\": 11.8,\r\n \"temperatureRate\": null,\r\n \"visibility\": null,\r\n \"visibilityRate\": null,\r\n \"windChill\": null,\r\n \"windSpeed\": 14.4,\r\n \"windDirection\": 290,\r\n \"windSpeedAvg\": null,\r\n \"windDirectionAvg\": null,\r\n \"windGustHourly\": null,\r\n \"windGustTimeLocalHourlyStr\": null,\r\n \"windGustTimeUtcHourlyStr\": null,\r\n \"windGustDirectionHourly\": null,\r\n \"windGustDaily\": null,\r\n \"windGustTimeLocalDailyStr\": null,\r\n \"windGustTimeUtcDailyStr\": null,\r\n \"windGustDirectionDaily\": null,\r\n \"observationTimeAdjustedLocalStr\": null,\r\n \"feelsLike\": 11.8\r\n}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:32 GMT"},{"request":{"method":"get","uri":"https://thepulseapi.earthnetworks.com/data/forecasts/v1/daily?access_token=KucXobMIyGIMjN8L0kJ4bpPg5GaV&location=39.1,77.1&locationtype=latitudelongitude&units=metric&verbose=true","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Sun, 13 Apr 2014 22:12:32 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Cache-Control":["no-cache"],"Content-Type":["application/json; charset=utf-8"],"Date":["Sun, 13 Apr 2014 22:12:34 GMT"],"Expires":["-1"],"Pragma":["no-cache"],"Server":["Microsoft-IIS/7.5"],"X-Aspnet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"Content-Length":["12087"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\r\n \"dailyForecastPeriods\": [\r\n {\r\n \"cloudCoverPercent\": 37,\r\n \"dewPoint\": -15.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 13,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 20.8,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 285,\r\n \"windSpeed\": 18.0,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 21C. Dew point will be around -15C with an average humidity of 13%. Winds will be 18 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-14T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-13T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 20,\r\n \"dewPoint\": -24.0,\r\n \"iconCode\": 70,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 6,\r\n \"summaryDescription\": \"Mostly Clear\",\r\n \"temperature\": 8.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 292,\r\n \"windSpeed\": 18.0,\r\n \"detailedDescription\": \"Mostly clear. Low temperature around 8C. Dew point will be around -24C with an average humidity of 6%. Winds will be 18 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-14T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-14T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 21,\r\n \"dewPoint\": -24.0,\r\n \"iconCode\": 26,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 5,\r\n \"summaryDescription\": \"Mostly Sunny\",\r\n \"temperature\": 22.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 273,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Mostly sunny. High temperature around 22C. Dew point will be around -24C with an average humidity of 5%. Winds will be 11 kph from the W.\",\r\n \"forecastDateLocalStr\": \"2014-04-15T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-14T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 42,\r\n \"dewPoint\": -22.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 6,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 7.4,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 282,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 7C. Dew point will be around -22C with an average humidity of 6%. Winds will be 7 kph from the WNW.\",\r\n \"forecastDateLocalStr\": \"2014-04-15T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-15T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 55,\r\n \"dewPoint\": -21.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 7,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 23.5,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 304,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 24C. Dew point will be around -21C with an average humidity of 7%. Winds will be 7 kph from the NW.\",\r\n \"forecastDateLocalStr\": \"2014-04-16T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-15T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 49,\r\n \"dewPoint\": -19.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 9,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 7.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 6,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 7C. Dew point will be around -19C with an average humidity of 9%. Winds will be 7 kph from the N.\",\r\n \"forecastDateLocalStr\": \"2014-04-16T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-16T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 71,\r\n \"dewPoint\": -16.0,\r\n \"iconCode\": 24,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 12,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 21.3,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 50,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Mostly cloudy. High temperature around 21C. Dew point will be around -16C with an average humidity of 12%. Winds will be 7 kph from the NE.\",\r\n \"forecastDateLocalStr\": \"2014-04-17T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-16T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 99,\r\n \"dewPoint\": -15.0,\r\n \"iconCode\": 13,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 11,\r\n \"summaryDescription\": \"Cloudy\",\r\n \"temperature\": 10.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 78,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Cloudy. Low temperature around 11C. Dew point will be around -15C with an average humidity of 11%. Winds will be 7 kph from the ENE.\",\r\n \"forecastDateLocalStr\": \"2014-04-17T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-17T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 69,\r\n \"dewPoint\": -11.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 14,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 22.0,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 44,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 22C. Dew point will be around -11C with an average humidity of 14%. Winds will be 11 kph from the NE.\",\r\n \"forecastDateLocalStr\": \"2014-04-18T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-17T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 78,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 19,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 10.9,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 82,\r\n \"windSpeed\": 14.4,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 11C. Dew point will be around -8C with an average humidity of 19%. Winds will be 14 kph from the E.\",\r\n \"forecastDateLocalStr\": \"2014-04-18T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-18T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 100,\r\n \"dewPoint\": -10.0,\r\n \"iconCode\": 1,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 17,\r\n \"summaryDescription\": \"Cloudy\",\r\n \"temperature\": 20.1,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 98,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Cloudy. High temperature around 20C. Dew point will be around -10C with an average humidity of 17%. Winds will be 7 kph from the E.\",\r\n \"forecastDateLocalStr\": \"2014-04-19T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-18T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 73,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 20,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 8.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 141,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 8C. Dew point will be around -8C with an average humidity of 20%. Winds will be 7 kph from the SE.\",\r\n \"forecastDateLocalStr\": \"2014-04-19T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-19T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 31,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 21,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 22.9,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 152,\r\n \"windSpeed\": 7.2,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 23C. Dew point will be around -8C with an average humidity of 21%. Winds will be 7 kph from the SSE.\",\r\n \"forecastDateLocalStr\": \"2014-04-20T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-19T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 21,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 70,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 18,\r\n \"summaryDescription\": \"Mostly Clear\",\r\n \"temperature\": 9.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 221,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly clear. Low temperature around 10C. Dew point will be around -8C with an average humidity of 18%. Winds will be 4 kph from the SW.\",\r\n \"forecastDateLocalStr\": \"2014-04-20T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-20T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 13,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 26,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 18,\r\n \"summaryDescription\": \"Mostly Sunny\",\r\n \"temperature\": 25.6,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 243,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly sunny. High temperature around 26C. Dew point will be around -8C with an average humidity of 18%. Winds will be 4 kph from the WSW.\",\r\n \"forecastDateLocalStr\": \"2014-04-21T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-20T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 87,\r\n \"dewPoint\": -9.0,\r\n \"iconCode\": 73,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 15,\r\n \"summaryDescription\": \"Mostly Cloudy\",\r\n \"temperature\": 11.1,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 72,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Mostly cloudy. Low temperature around 11C. Dew point will be around -9C with an average humidity of 15%. Winds will be 4 kph from the ENE.\",\r\n \"forecastDateLocalStr\": \"2014-04-21T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-21T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n },\r\n {\r\n \"cloudCoverPercent\": 52,\r\n \"dewPoint\": -10.0,\r\n \"iconCode\": 3,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 14,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 27.2,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 223,\r\n \"windSpeed\": 3.6,\r\n \"detailedDescription\": \"Partly cloudy. High temperature around 27C. Dew point will be around -10C with an average humidity of 14%. Winds will be 4 kph from the SW.\",\r\n \"forecastDateLocalStr\": \"2014-04-22T07:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-21T23:00:00Z\",\r\n \"isNightTimePeriod\": false\r\n },\r\n {\r\n \"cloudCoverPercent\": 36,\r\n \"dewPoint\": -8.0,\r\n \"iconCode\": 2,\r\n \"precipCode\": 1,\r\n \"precipProbability\": 0,\r\n \"relativeHumidity\": 15,\r\n \"summaryDescription\": \"Partly Cloudy\",\r\n \"temperature\": 14.5,\r\n \"thunderstormProbability\": 0,\r\n \"windDirectionDegrees\": 275,\r\n \"windSpeed\": 10.8,\r\n \"detailedDescription\": \"Partly cloudy. Low temperature around 15C. Dew point will be around -8C with an average humidity of 15%. Winds will be 11 kph from the W.\",\r\n \"forecastDateLocalStr\": \"2014-04-22T19:00:00\",\r\n \"forecastDateUtcStr\": \"2014-04-22T11:00:00Z\",\r\n \"isNightTimePeriod\": true\r\n }\r\n ],\r\n \"forecastCreatedUtcStr\": \"2014-04-13T12:01:00.0000000Z\",\r\n \"location\": \"CH13B0005\",\r\n \"locationType\": \"city\"\r\n}"},"http_version":null},"recorded_at":"Sun, 13 Apr 2014 22:12:33 GMT"}],"recorded_with":"VCR 2.9.0"}
|
data/spec/spec_helper.rb
CHANGED
@@ -8,18 +8,22 @@ require_relative '../lib/barometer/weather_bug'
|
|
8
8
|
|
9
9
|
Dir['./spec/support/**/*.rb'].sort.each {|f| require f}
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
downcased_weatherbug_code[0] = WEATHERBUG_CODE.to_s[0..0].downcase
|
11
|
+
WEATHERBUG_CLIENT_ID = Barometer::Support::KeyFileParser.find(:weather_bug, :client_id) || 'weatherbug_id'
|
12
|
+
WEATHERBUG_CLIENT_SECRET = Barometer::Support::KeyFileParser.find(:weather_bug, :client_secret) || 'weatherbug_secret'
|
14
13
|
|
15
14
|
VCR.configure do |config|
|
16
15
|
config.cassette_library_dir = 'spec/cassettes'
|
17
16
|
config.hook_into :webmock
|
18
17
|
config.default_cassette_options = { record: :none, serialize_with: :json }
|
19
18
|
|
20
|
-
config.filter_sensitive_data('
|
21
|
-
|
22
|
-
config.filter_sensitive_data('
|
19
|
+
config.filter_sensitive_data('WEATHERBUG_CLIENT_ID') { WEATHERBUG_CLIENT_ID.to_s }
|
20
|
+
config.filter_sensitive_data('WEATHERBUG_CLIENT_SECRET') { WEATHERBUG_CLIENT_SECRET.to_s }
|
21
|
+
config.filter_sensitive_data('WEATHERBUG_ACCESS_CODE') do |interaction|
|
22
|
+
if !defined?(WEATHERBUG_ACCESS_CODE) && interaction.request.uri =~ /thepulseapi.earthnetworks.com\/oauth20\/token/
|
23
|
+
WEATHERBUG_ACCESS_CODE = JSON.parse(interaction.response.body)['OAuth20']['access_token']['token']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
config.filter_sensitive_data('WEATHERBUG_ACCESS_CODE') { defined?(WEATHERBUG_ACCESS_CODE) ? WEATHERBUG_ACCESS_CODE.to_s : 'this_should_not_match' }
|
23
27
|
|
24
28
|
config.configure_rspec_metadata!
|
25
29
|
end
|
@@ -3,62 +3,14 @@ require_relative '../spec_helper'
|
|
3
3
|
module Barometer
|
4
4
|
describe WeatherBug::CurrentResponse do
|
5
5
|
it "parses the timezones correctly" do
|
6
|
-
payload = Barometer::Utils::Payload.new(
|
7
|
-
'
|
8
|
-
|
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
|
-
})
|
6
|
+
payload = Barometer::Utils::Payload.new(
|
7
|
+
'observationTimeUtcStr' => '2013-05-18T17:46:00'
|
8
|
+
)
|
17
9
|
response = WeatherBug::CurrentResponse.new.parse(payload)
|
18
10
|
|
19
11
|
utc_observed_at = Time.utc(2013,5,18,17,46,0)
|
20
|
-
utc_stale_at = Time.utc(2013,5,18,18,46,0)
|
21
12
|
|
22
13
|
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
14
|
end
|
63
15
|
end
|
64
16
|
end
|
@@ -5,16 +5,15 @@ module Barometer
|
|
5
5
|
let(:current_response) { Barometer::Response.new }
|
6
6
|
|
7
7
|
it "parses the timezones correctly" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
})
|
8
|
+
payload = Barometer::Utils::Payload.new(
|
9
|
+
"dailyForecastPeriods" => [
|
10
|
+
"forecastDateUtcStr" => "2014-04-13T23:00:00Z"
|
11
|
+
]
|
12
|
+
)
|
14
13
|
response = WeatherBug::ForecastResponse.new(current_response).parse(payload)
|
15
14
|
|
16
|
-
utc_starts_at = Time.utc(
|
17
|
-
utc_ends_at = Time.utc(
|
15
|
+
utc_starts_at = Time.utc(2014,4,13,23,0,0)
|
16
|
+
utc_ends_at = Time.utc(2014,4,14,10,59,59)
|
18
17
|
|
19
18
|
expect( response.forecast[0].starts_at.utc ).to eq utc_starts_at
|
20
19
|
expect( response.forecast[0].ends_at.utc ).to eq utc_ends_at
|
@@ -6,21 +6,13 @@ module Barometer
|
|
6
6
|
let(:converted_query) { double(:converted_query).as_null_object }
|
7
7
|
let(:query) { WeatherBug::Query.new(converted_query) }
|
8
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
9
|
context 'and the query is a :coordinates' do
|
18
10
|
let(:geo) { double(:geo, latitude: '11.22', longitude: '33.44') }
|
19
11
|
before { converted_query.stub(format: :coordinates, geo: geo) }
|
20
12
|
|
21
13
|
it 'includes the correct parameters' do
|
22
|
-
expect( query.to_param[:
|
23
|
-
expect( query.to_param[:
|
14
|
+
expect( query.to_param[:locationtype] ).to eq 'latitudelongitude'
|
15
|
+
expect( query.to_param[:location] ).to eq '11.22,33.44'
|
24
16
|
end
|
25
17
|
end
|
26
18
|
|
@@ -28,7 +20,7 @@ module Barometer
|
|
28
20
|
before { converted_query.stub(metric?: true) }
|
29
21
|
|
30
22
|
it 'includes the correct parameters' do
|
31
|
-
expect( query.to_param[:
|
23
|
+
expect( query.to_param[:units] ).to eq 'metric'
|
32
24
|
end
|
33
25
|
end
|
34
26
|
|
@@ -36,7 +28,7 @@ module Barometer
|
|
36
28
|
before { converted_query.stub(metric?: false) }
|
37
29
|
|
38
30
|
it 'includes the correct parameters' do
|
39
|
-
expect( query.to_param[:
|
31
|
+
expect( query.to_param[:units] ).to eq 'english'
|
40
32
|
end
|
41
33
|
end
|
42
34
|
end
|
data/spec/weather_bug_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative 'spec_helper'
|
|
2
2
|
|
3
3
|
module Barometer
|
4
4
|
describe WeatherBug, vcr: {
|
5
|
-
cassette_name: '
|
5
|
+
cassette_name: 'WeatherBug'
|
6
6
|
} do
|
7
7
|
|
8
8
|
it 'auto-registers this weather service as :weather_bug' do
|
@@ -10,9 +10,9 @@ module Barometer
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.call' do
|
13
|
-
|
14
|
-
let(:query) { build_query }
|
13
|
+
let(:query) { build_query }
|
15
14
|
|
15
|
+
context 'when no keys are provided' do
|
16
16
|
it 'raises an error' do
|
17
17
|
expect {
|
18
18
|
WeatherBug.call(query)
|
@@ -21,58 +21,63 @@ module Barometer
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when keys are provided' do
|
24
|
-
let(:
|
25
|
-
|
26
|
-
|
24
|
+
let(:config) do
|
25
|
+
{
|
26
|
+
keys: {
|
27
|
+
client_id: WEATHERBUG_CLIENT_ID,
|
28
|
+
client_secret: WEATHERBUG_CLIENT_SECRET
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
let(:converted_query) do
|
33
|
+
ConvertedQuery.new('39.1,77.1', :coordinates, :metric)
|
34
|
+
end
|
27
35
|
|
28
36
|
subject { WeatherBug.call(query, config) }
|
29
37
|
|
38
|
+
before do
|
39
|
+
allow(query).to receive(:convert!).with(:coordinates).
|
40
|
+
and_return(converted_query)
|
41
|
+
end
|
42
|
+
|
30
43
|
it 'converts the query to accepted formats' do
|
31
|
-
|
32
|
-
|
44
|
+
WeatherBug.call(query, config)
|
45
|
+
|
46
|
+
expect(query).to have_received(:convert!).with(:coordinates).at_least(:once)
|
33
47
|
end
|
34
48
|
|
35
49
|
it 'includes the expected data' do
|
36
|
-
|
37
|
-
|
38
|
-
expect(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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)
|
50
|
+
result = WeatherBug.call(query, config)
|
51
|
+
|
52
|
+
expect(result.query).to eq '39.1,77.1'
|
53
|
+
expect(result.format).to eq :coordinates
|
54
|
+
expect(result).to be_metric
|
55
|
+
|
56
|
+
expect(result).to have_data(:current, :observed_at).as_format(:time)
|
57
|
+
|
58
|
+
expect(result).to have_data(:current, :humidity).as_format(:float)
|
59
|
+
expect(result).to have_data(:current, :icon).as_format(:number)
|
60
|
+
expect(result).to have_data(:current, :temperature).as_format(:temperature)
|
61
|
+
expect(result).to have_data(:current, :dew_point).as_format(:temperature)
|
62
|
+
expect(result).to have_data(:current, :wind).as_format(:vector)
|
63
|
+
|
64
|
+
expect( subject.forecast.size ).to eq 18
|
65
|
+
|
66
|
+
day_forcast = subject.forecast.find{ |p| !p.high.nil? }
|
67
|
+
expect(day_forcast).to have_data(:high).as_format(:temperature)
|
68
|
+
expect(day_forcast).to have_data(:starts_at).as_format(:time)
|
69
|
+
expect(day_forcast).to have_data(:ends_at).as_format(:time)
|
70
|
+
expect(day_forcast).to have_data(:condition).as_format(:string)
|
71
|
+
expect(day_forcast).to have_data(:icon).as_format(:number)
|
72
|
+
expect(day_forcast).to have_data(:pop).as_format(:float)
|
73
|
+
|
74
|
+
night_forcast = subject.forecast.find{ |p| !p.low.nil? }
|
75
|
+
expect(night_forcast).to have_data(:low).as_format(:temperature)
|
76
|
+
expect(night_forcast).to have_data(:starts_at).as_format(:time)
|
77
|
+
expect(night_forcast).to have_data(:ends_at).as_format(:time)
|
78
|
+
expect(night_forcast).to have_data(:condition).as_format(:string)
|
79
|
+
expect(night_forcast).to have_data(:icon).as_format(:number)
|
80
|
+
expect(night_forcast).to have_data(:pop).as_format(:float)
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barometer-weather_bug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Gangl
|
@@ -58,16 +58,13 @@ files:
|
|
58
58
|
- lib/barometer/weather_bug/current_response.rb
|
59
59
|
- lib/barometer/weather_bug/forecast_api.rb
|
60
60
|
- lib/barometer/weather_bug/forecast_response.rb
|
61
|
+
- lib/barometer/weather_bug/oauth_api.rb
|
62
|
+
- lib/barometer/weather_bug/oauth_token.rb
|
61
63
|
- lib/barometer/weather_bug/query.rb
|
62
64
|
- lib/barometer/weather_bug/response/current_weather.rb
|
63
65
|
- lib/barometer/weather_bug/response/forecasted_weather.rb
|
64
|
-
- lib/barometer/weather_bug/response/location.rb
|
65
|
-
- lib/barometer/weather_bug/response/station.rb
|
66
|
-
- lib/barometer/weather_bug/response/sun.rb
|
67
|
-
- lib/barometer/weather_bug/response/time_helper.rb
|
68
|
-
- lib/barometer/weather_bug/response/timezone.rb
|
69
66
|
- lib/barometer/weather_bug/version.rb
|
70
|
-
- spec/cassettes/
|
67
|
+
- spec/cassettes/WeatherBug.json
|
71
68
|
- spec/spec_helper.rb
|
72
69
|
- spec/weather_bug/current_response_spec.rb
|
73
70
|
- spec/weather_bug/forecast_response_spec.rb
|
@@ -98,7 +95,7 @@ signing_key:
|
|
98
95
|
specification_version: 4
|
99
96
|
summary: A barometer adapter for WeatherBug
|
100
97
|
test_files:
|
101
|
-
- spec/cassettes/
|
98
|
+
- spec/cassettes/WeatherBug.json
|
102
99
|
- spec/spec_helper.rb
|
103
100
|
- spec/weather_bug/current_response_spec.rb
|
104
101
|
- spec/weather_bug/forecast_response_spec.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Barometer
|
2
|
-
class WeatherBug
|
3
|
-
class Response
|
4
|
-
class Location < WeatherService::Response::Location
|
5
|
-
private
|
6
|
-
|
7
|
-
def city
|
8
|
-
payload.fetch('location', 'city')
|
9
|
-
end
|
10
|
-
|
11
|
-
def state_code
|
12
|
-
payload.fetch('location', 'state')
|
13
|
-
end
|
14
|
-
|
15
|
-
def zip_code
|
16
|
-
payload.fetch('location', 'zip')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Barometer
|
2
|
-
class WeatherBug
|
3
|
-
class Response
|
4
|
-
class Station < WeatherService::Response::Location
|
5
|
-
private
|
6
|
-
|
7
|
-
def id
|
8
|
-
payload.fetch('station_id')
|
9
|
-
end
|
10
|
-
|
11
|
-
def name
|
12
|
-
payload.fetch('station')
|
13
|
-
end
|
14
|
-
|
15
|
-
def city
|
16
|
-
payload.using(/^([\w ]*?),/).fetch('city_state')
|
17
|
-
end
|
18
|
-
|
19
|
-
def state_code
|
20
|
-
payload.using(/^[\w ^,]*?,([\w ^,]*)/).fetch('city_state')
|
21
|
-
end
|
22
|
-
|
23
|
-
def country
|
24
|
-
payload.fetch('country')
|
25
|
-
end
|
26
|
-
|
27
|
-
def zip_code
|
28
|
-
payload.fetch('city_state', '@zipcode')
|
29
|
-
end
|
30
|
-
|
31
|
-
def latitude
|
32
|
-
payload.fetch('latitude')
|
33
|
-
end
|
34
|
-
|
35
|
-
def longitude
|
36
|
-
payload.fetch('longitude')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require_relative 'time_helper'
|
2
|
-
|
3
|
-
module Barometer
|
4
|
-
class WeatherBug
|
5
|
-
class Response
|
6
|
-
class Sun
|
7
|
-
def initialize(payload, timezone)
|
8
|
-
@payload = payload
|
9
|
-
@timezone = timezone
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse
|
13
|
-
Data::Sun.new(rise: local_sunrise_time, set: local_sunset_time)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :payload, :timezone
|
19
|
-
|
20
|
-
def local_sunrise_time
|
21
|
-
TimeHelper.new(payload, timezone).parse('sunrise')
|
22
|
-
end
|
23
|
-
|
24
|
-
def local_sunset_time
|
25
|
-
TimeHelper.new(payload, timezone).parse('sunset')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Barometer
|
2
|
-
class WeatherBug
|
3
|
-
class Response
|
4
|
-
class TimeHelper
|
5
|
-
def initialize(payload, timezone)
|
6
|
-
@payload = payload
|
7
|
-
@timezone = timezone
|
8
|
-
end
|
9
|
-
|
10
|
-
def parse(key)
|
11
|
-
return unless local_time(key)
|
12
|
-
timezone.local_to_utc(local_time(key))
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
attr_reader :payload, :timezone, :key
|
18
|
-
|
19
|
-
def local_time(key)
|
20
|
-
@key = key
|
21
|
-
@local_time ||= Utils::Time.parse(year, month, day, hour, minute, second)
|
22
|
-
end
|
23
|
-
|
24
|
-
def year
|
25
|
-
payload.fetch(key, 'year', '@number')
|
26
|
-
end
|
27
|
-
|
28
|
-
def month
|
29
|
-
payload.fetch(key, 'month', '@number')
|
30
|
-
end
|
31
|
-
|
32
|
-
def day
|
33
|
-
payload.fetch(key, 'day', '@number')
|
34
|
-
end
|
35
|
-
|
36
|
-
def hour
|
37
|
-
payload.fetch(key, 'hour', '@hour_24')
|
38
|
-
end
|
39
|
-
|
40
|
-
def minute
|
41
|
-
payload.fetch(key, 'minute', '@number')
|
42
|
-
end
|
43
|
-
|
44
|
-
def second
|
45
|
-
payload.fetch(key, 'second', '@number')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
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"}
|