barometer 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +2 -5
  3. data/Gemfile +11 -7
  4. data/LICENSE +1 -1
  5. data/README.md +3 -3
  6. data/barometer.gemspec +7 -10
  7. data/lib/barometer/utils/json_reader.rb +2 -3
  8. data/lib/barometer/utils/payload.rb +6 -87
  9. data/lib/barometer/utils/translations/zone_codes.yml +1 -0
  10. data/lib/barometer/version.rb +1 -1
  11. data/lib/barometer/weather_service.rb +0 -1
  12. data/spec/barometer_spec.rb +6 -0
  13. data/spec/spec_helper.rb +0 -11
  14. data/spec/utils/payload_spec.rb +20 -153
  15. data/spec/weather_services/wunderground_v1/current_response_spec.rb +5 -4
  16. data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +23 -22
  17. metadata +32 -170
  18. data/.pelusa.yml +0 -7
  19. data/lib/barometer/weather_services/weather_bug.rb +0 -41
  20. data/lib/barometer/weather_services/weather_bug/current_api.rb +0 -26
  21. data/lib/barometer/weather_services/weather_bug/current_response.rb +0 -33
  22. data/lib/barometer/weather_services/weather_bug/forecast_api.rb +0 -26
  23. data/lib/barometer/weather_services/weather_bug/forecast_response.rb +0 -29
  24. data/lib/barometer/weather_services/weather_bug/query.rb +0 -42
  25. data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +0 -82
  26. data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +0 -67
  27. data/lib/barometer/weather_services/weather_bug/response/location.rb +0 -23
  28. data/lib/barometer/weather_services/weather_bug/response/station.rb +0 -43
  29. data/lib/barometer/weather_services/weather_bug/response/sun.rb +0 -32
  30. data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +0 -52
  31. data/lib/barometer/weather_services/weather_bug/response/timezone.rb +0 -15
  32. data/spec/cassettes/WeatherService_WeatherBug.json +0 -1
  33. data/spec/weather_services/weather_bug/current_response_spec.rb +0 -64
  34. data/spec/weather_services/weather_bug/forecast_response_spec.rb +0 -23
  35. data/spec/weather_services/weather_bug/query_spec.rb +0 -44
  36. data/spec/weather_services/weather_bug_spec.rb +0 -80
@@ -1,7 +0,0 @@
1
- sources: lib/**/*.rb
2
-
3
- lints:
4
- InstanceVariables:
5
- limit: 3
6
- LineRestriction:
7
- limit: 80
@@ -1,41 +0,0 @@
1
- require_relative 'weather_bug/current_api'
2
- require_relative 'weather_bug/current_response'
3
- require_relative 'weather_bug/forecast_api'
4
- require_relative 'weather_bug/forecast_response'
5
-
6
- module Barometer
7
- module WeatherService
8
- class WeatherBug
9
- def self.call(query, config={})
10
- WeatherBug.new(query, config).measure!
11
- end
12
-
13
- def initialize(query, config={})
14
- @query = query
15
- @api_code = config[:keys][:code] if config[:keys]
16
- end
17
-
18
- def measure!
19
- validate_key!
20
-
21
- current_weather_api = CurrentApi.new(query, api_code)
22
- response = CurrentResponse.new.parse(current_weather_api.get)
23
-
24
- forecast_weather_api = ForecastApi.new(current_weather_api.query, api_code)
25
- ForecastResponse.new(response).parse(forecast_weather_api.get)
26
- end
27
-
28
- private
29
-
30
- attr_reader :query, :api_code
31
-
32
- def validate_key!
33
- unless api_code && !api_code.empty?
34
- raise KeyRequired
35
- end
36
- end
37
- end
38
- end
39
- end
40
-
41
- Barometer::WeatherService.register(:weather_bug, Barometer::WeatherService::WeatherBug)
@@ -1,26 +0,0 @@
1
- require_relative 'query'
2
-
3
- module Barometer
4
- module WeatherService
5
- class WeatherBug
6
- class CurrentApi < Utils::Api
7
- def initialize(query, api_code)
8
- @query = WeatherBug::Query.new(query)
9
- @api_code = api_code
10
- end
11
-
12
- def url
13
- "http://#{@api_code}.api.wxbug.net/getLiveWeatherRSS.aspx"
14
- end
15
-
16
- def params
17
- {ACode: @api_code, OutputType: '1'}.merge(@query.to_param)
18
- end
19
-
20
- def unwrap_nodes
21
- ['weather', 'ob']
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- require_relative 'response/timezone'
2
- require_relative 'response/current_weather'
3
- require_relative 'response/station'
4
-
5
- module Barometer
6
- module WeatherService
7
- class WeatherBug
8
- class CurrentResponse
9
- def initialize
10
- @response = Barometer::Response.new
11
- end
12
-
13
- def parse(payload)
14
- response.add_query(payload.query)
15
-
16
- response.timezone = WeatherBug::Response::TimeZone.new(payload).parse
17
- response.current = WeatherBug::Response::CurrentWeather.new(payload, timezone).parse
18
- response.station = WeatherBug::Response::Station.new(payload).parse
19
-
20
- response
21
- end
22
-
23
- private
24
-
25
- attr_reader :response
26
-
27
- def timezone
28
- response.timezone
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,26 +0,0 @@
1
- require_relative 'query'
2
-
3
- module Barometer
4
- module WeatherService
5
- class WeatherBug
6
- class ForecastApi < Utils::Api
7
- def initialize(query, api_code)
8
- @query = WeatherBug::Query.new(query)
9
- @api_code = api_code
10
- end
11
-
12
- def url
13
- "http://#{@api_code}.api.wxbug.net/getForecastRSS.aspx"
14
- end
15
-
16
- def params
17
- {ACode: @api_code, OutputType: '1'}.merge(@query.to_param)
18
- end
19
-
20
- def unwrap_nodes
21
- ['weather', 'forecasts']
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,29 +0,0 @@
1
- require_relative 'response/forecasted_weather'
2
- require_relative 'response/location'
3
-
4
- module Barometer
5
- module WeatherService
6
- class WeatherBug
7
- class ForecastResponse
8
- def initialize(response)
9
- @response = response
10
- end
11
-
12
- def parse(payload)
13
- response.forecast = WeatherBug::Response::ForecastedWeather.new(payload, timezone).parse
14
- response.location = WeatherBug::Response::Location.new(payload).parse
15
-
16
- response
17
- end
18
-
19
- private
20
-
21
- attr_reader :response
22
-
23
- def timezone
24
- response.timezone
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,42 +0,0 @@
1
- require 'delegate'
2
-
3
- module Barometer
4
- module WeatherService
5
- class WeatherBug
6
- class Query < SimpleDelegator
7
- attr_reader :converted_query
8
-
9
- def self.accepted_formats
10
- [:short_zipcode, :coordinates]
11
- end
12
-
13
- def initialize(query)
14
- super
15
- @converted_query = convert_query
16
- end
17
-
18
- def to_param
19
- {UnitType: unit_type}.merge(format_query)
20
- end
21
-
22
- private
23
-
24
- def convert_query
25
- convert!(*self.class.accepted_formats)
26
- end
27
-
28
- def format_query
29
- if converted_query.format == :short_zipcode
30
- {zipCode: converted_query.q}
31
- else
32
- {lat: converted_query.geo.latitude, long: converted_query.geo.longitude}
33
- end
34
- end
35
-
36
- def unit_type
37
- converted_query.metric? ? '1' : '0'
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,82 +0,0 @@
1
- require_relative 'time_helper'
2
- require_relative 'sun'
3
-
4
- module Barometer
5
- module WeatherService
6
- class WeatherBug
7
- class Response
8
- class CurrentWeather
9
- def initialize(payload, timezone)
10
- @payload = payload
11
- @timezone = timezone
12
- @current = Barometer::Response::Current.new
13
- end
14
-
15
- def parse
16
- current.observed_at = observed_at
17
- current.stale_at = stale_at
18
- current.humidity = humidity
19
- current.condition = condition
20
- current.icon = icon
21
- current.temperature = temperature
22
- current.dew_point = dew_point
23
- current.wind_chill = wind_chill
24
- current.wind = wind
25
- current.pressure = pressure
26
- current.sun = WeatherBug::Response::Sun.new(payload, timezone).parse
27
-
28
- current
29
- end
30
-
31
- private
32
-
33
- attr_reader :payload, :timezone, :current
34
-
35
- def units
36
- payload.units
37
- end
38
-
39
- def observed_at
40
- @observed_at ||= TimeHelper.new(payload, timezone).parse('ob_date')
41
- end
42
-
43
- def stale_at
44
- Utils::Time.add_one_hour(observed_at)
45
- end
46
-
47
- def humidity
48
- payload.fetch('humidity')
49
- end
50
-
51
- def condition
52
- payload.fetch('current_condition')
53
- end
54
-
55
- def icon
56
- payload.using(/cond(\d*)\.gif/).fetch('current_condition', '@icon')
57
- end
58
-
59
- def temperature
60
- [units, payload.fetch('temp')]
61
- end
62
-
63
- def dew_point
64
- [units, payload.fetch('dew_point')]
65
- end
66
-
67
- def wind_chill
68
- [units, payload.fetch('feels_like')]
69
- end
70
-
71
- def wind
72
- [units, payload.fetch('wind_speed'), payload.fetch('wind_direction_degrees')]
73
- end
74
-
75
- def pressure
76
- [units, payload.fetch('pressure')]
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,67 +0,0 @@
1
- module Barometer
2
- module WeatherService
3
- class WeatherBug
4
- class Response
5
- class ForecastedWeather
6
- def initialize(payload, timezone)
7
- @payload = payload
8
- @timezone = timezone
9
- @predictions = Barometer::Response::PredictionCollection.new
10
- end
11
-
12
- def parse
13
- each_prediction do |prediction, forecast_payload, index|
14
- prediction.date = date(index), timezone
15
- prediction.condition = condition(forecast_payload)
16
- prediction.icon = icon(forecast_payload)
17
- prediction.high = high(forecast_payload)
18
- prediction.low = low(forecast_payload)
19
- end
20
-
21
- predictions
22
- end
23
-
24
- private
25
-
26
- attr_reader :payload, :timezone, :predictions
27
-
28
- def units
29
- payload.units
30
- end
31
-
32
- def each_prediction
33
- payload.fetch_each_with_index('forecast') do |forecast_payload, index|
34
- predictions.build do |prediction|
35
- yield prediction, forecast_payload, index
36
- end
37
- end
38
- end
39
-
40
- def start_date
41
- Date.strptime(payload.fetch('@date'), '%m/%d/%Y %H:%M:%S %p')
42
- end
43
-
44
- def date(index)
45
- start_date + index
46
- end
47
-
48
- def condition(forecast_payload)
49
- forecast_payload.fetch('short_prediction')
50
- end
51
-
52
- def icon(forecast_payload)
53
- forecast_payload.using(/cond0*([1-9][0-9]*)\.gif$/).fetch('image')
54
- end
55
-
56
- def high(forecast_payload)
57
- [units, forecast_payload.fetch('high')]
58
- end
59
-
60
- def low(forecast_payload)
61
- [units, forecast_payload.fetch('low')]
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,23 +0,0 @@
1
- module Barometer
2
- module WeatherService
3
- class WeatherBug
4
- class Response
5
- class Location < WeatherService::Response::Location
6
- private
7
-
8
- def city
9
- payload.fetch('location', 'city')
10
- end
11
-
12
- def state_code
13
- payload.fetch('location', 'state')
14
- end
15
-
16
- def zip_code
17
- payload.fetch('location', 'zip')
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- module Barometer
2
- module WeatherService
3
- class WeatherBug
4
- class Response
5
- class Station < WeatherService::Response::Location
6
- private
7
-
8
- def id
9
- payload.fetch('station_id')
10
- end
11
-
12
- def name
13
- payload.fetch('station')
14
- end
15
-
16
- def city
17
- payload.using(/^([\w ]*?),/).fetch('city_state')
18
- end
19
-
20
- def state_code
21
- payload.using(/^[\w ^,]*?,([\w ^,]*)/).fetch('city_state')
22
- end
23
-
24
- def country
25
- payload.fetch('country')
26
- end
27
-
28
- def zip_code
29
- payload.fetch('city_state', '@zipcode')
30
- end
31
-
32
- def latitude
33
- payload.fetch('latitude')
34
- end
35
-
36
- def longitude
37
- payload.fetch('longitude')
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,32 +0,0 @@
1
- require_relative 'time_helper'
2
-
3
- module Barometer
4
- module WeatherService
5
- class WeatherBug
6
- class Response
7
- class Sun
8
- def initialize(payload, timezone)
9
- @payload = payload
10
- @timezone = timezone
11
- end
12
-
13
- def parse
14
- Data::Sun.new(rise: local_sunrise_time, set: local_sunset_time)
15
- end
16
-
17
- private
18
-
19
- attr_reader :payload, :timezone
20
-
21
- def local_sunrise_time
22
- TimeHelper.new(payload, timezone).parse('sunrise')
23
- end
24
-
25
- def local_sunset_time
26
- TimeHelper.new(payload, timezone).parse('sunset')
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end