duststorm 0.0.1

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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +1 -0
  7. data/duststorm.gemspec +31 -0
  8. data/lib/duststorm/attribute/coordinate.rb +9 -0
  9. data/lib/duststorm/attribute/time.rb +10 -0
  10. data/lib/duststorm/attribute.rb +9 -0
  11. data/lib/duststorm/base.rb +21 -0
  12. data/lib/duststorm/forecast/base.rb +15 -0
  13. data/lib/duststorm/forecast.rb +11 -0
  14. data/lib/duststorm/utils/response_mapper.rb +73 -0
  15. data/lib/duststorm/utils.rb +6 -0
  16. data/lib/duststorm/version.rb +3 -0
  17. data/lib/duststorm/weather/base.rb +11 -0
  18. data/lib/duststorm/weather/current.rb +7 -0
  19. data/lib/duststorm/weather/daily.rb +11 -0
  20. data/lib/duststorm/weather/hourly.rb +9 -0
  21. data/lib/duststorm/weather.rb +11 -0
  22. data/lib/duststorm/weather_api.rb +23 -0
  23. data/lib/duststorm/weather_apis/base.rb +39 -0
  24. data/lib/duststorm/weather_apis/forecast_io.rb +55 -0
  25. data/lib/duststorm/weather_apis/wunderground.rb +6 -0
  26. data/lib/duststorm.rb +25 -0
  27. data/spec/cassettes/forecast_for_forecast_io.yml +1159 -0
  28. data/spec/cassettes/forecast_for_wunderground.yml +581 -0
  29. data/spec/duststorm/base_spec.rb +26 -0
  30. data/spec/duststorm/forecast/base_spec.rb +50 -0
  31. data/spec/duststorm/forecast_spec.rb +18 -0
  32. data/spec/duststorm/version_spec.rb +7 -0
  33. data/spec/duststorm/weather/hourly_spec.rb +28 -0
  34. data/spec/duststorm/weather_api_spec.rb +12 -0
  35. data/spec/duststorm_spec.rb +25 -0
  36. data/spec/features/weather_services_spec.rb +83 -0
  37. data/spec/spec_helper.rb +24 -0
  38. data/spec/support/have_keys.rb +10 -0
  39. data/spec/support/matchers/be_a_forecast_json_matcher.rb +19 -0
  40. metadata +221 -0
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module Duststorm
4
+ describe Forecast do
5
+ describe '.new' do
6
+ before do
7
+ allow(Forecast::Base).to receive(:new)
8
+ end
9
+
10
+ it 'delegates the call to Base class' do
11
+ expect(Forecast::Base).to receive(:new).with('args')
12
+
13
+ Forecast.new('args')
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Duststorm::VERSION do
4
+ it 'should be the correct version' do
5
+ expect(Duststorm::VERSION).to eq('0.0.1')
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Duststorm
4
+ module Weather
5
+ describe Hourly do
6
+ let(:hourly_hash) do
7
+ {
8
+ time: 1427320800,
9
+ summary: "Clear",
10
+ precipIntensity: 0,
11
+ precipitation: 0,
12
+ temperature: 64.78,
13
+ apparentTemperature: 64.78,
14
+ }
15
+ end
16
+
17
+ let(:hourly) { Hourly.new(hourly_hash) }
18
+
19
+ describe '#attributes' do
20
+ it 'has the proper attributes' do
21
+ expect(hourly.time).to eq Time.at(1427320800)
22
+ expect(hourly.precipitation).to eq 0.0
23
+ expect(hourly.temperature).to eq 64.78
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ module Duststorm
4
+ describe WeatherApi do
5
+ describe '.response' do
6
+
7
+ end
8
+
9
+ describe 'klass' do
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Duststorm do
4
+ describe '#new' do
5
+ before do
6
+ allow(Duststorm::Base).to receive(:new)
7
+ end
8
+
9
+ it 'delegates the call to Base class' do
10
+ expect(Duststorm::Base).to receive(:new).with('args')
11
+ Duststorm.new('args')
12
+ end
13
+ end
14
+
15
+ describe '.config' do
16
+ it 'has an empty hash default value' do
17
+ expect( Duststorm.config ).to be {}
18
+ end
19
+
20
+ it 'sets a value' do
21
+ Duststorm.config = { forecast: 'api-key' }
22
+ expect( Duststorm.config ).to eq({ forecast: 'api-key' })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ForecastIo forecast' do
4
+ let(:lat) { '37.8267' }
5
+ let(:lng) { '-122.423' }
6
+ let(:options) { {} }
7
+
8
+ let(:forecast) { Duststorm.new(lat, lng, options).forecast }
9
+
10
+ before do
11
+ Duststorm.config = weather_service_config
12
+ end
13
+
14
+ around(:each) do |example|
15
+ VCR.use_cassette(vcr_cassette, record: :once) do
16
+ example.run
17
+ end
18
+ end
19
+
20
+ describe 'forecast_io response' do
21
+ let(:vcr_cassette) { 'forecast_for_forecast_io' }
22
+
23
+ let(:weather_service_config) { { forecast_io: 'some-api-key' } }
24
+ let(:weather_services_response) do
25
+ Duststorm::WeatherApi::ForecastIo.new(lat, lng, options).execute
26
+ end
27
+
28
+ it 'has the correct keys' do
29
+ expect(weather_services_response).to be_a_forecast_json
30
+ end
31
+
32
+ it 'maps the proper attributes' do
33
+ expect_proper_api_mapping
34
+ end
35
+
36
+ it 'sets the proper weather types' do
37
+ expect_proper_weather_types
38
+ end
39
+ end
40
+
41
+ xdescribe 'wunderground response' do
42
+ let(:vcr_cassette) { 'forecast_for_wunderground' }
43
+
44
+ let(:weather_service_config) { { wunderground: '' } }
45
+ let(:weather_services_response) do
46
+ Duststorm::WeatherApi::Wunderground.new(lat, lng, options).execute
47
+ end
48
+
49
+ it 'maps the proper attributes' do
50
+ expect_proper_api_mapping
51
+ end
52
+
53
+ it 'sets the proper weather types' do
54
+ expect_proper_weather_types
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def expect_proper_api_mapping
61
+ expect(forecast.latitude).to eq(37.8267)
62
+ expect(forecast.longitude).to eq(-122.423)
63
+
64
+ expect(forecast.currently.temperature).to eq(
65
+ weather_services_response[:currently][:temperature]
66
+ )
67
+
68
+ expect(forecast.hourly.size).to eq(
69
+ weather_services_response[:hourly].size
70
+ )
71
+
72
+ expect(forecast.daily.size).to eq(
73
+ weather_services_response[:daily].size
74
+ )
75
+ end
76
+
77
+ def expect_proper_weather_types
78
+ expect(forecast).to be_a(Duststorm::Forecast::Base)
79
+ expect(forecast.currently).to be_a(Duststorm::Weather::Current)
80
+ expect(forecast.hourly.first).to be_a(Duststorm::Weather::Hourly)
81
+ expect(forecast.daily.first).to be_a(Duststorm::Weather::Daily)
82
+ end
83
+ end
@@ -0,0 +1,24 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+ require 'duststorm'
4
+
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
+
7
+ require 'vcr'
8
+ require 'typhoeus/adapters/faraday'
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'spec/cassettes'
12
+ c.hook_into :typhoeus
13
+ c.allow_http_connections_when_no_cassette = false
14
+ end
15
+
16
+ Faraday.default_adapter = :typhoeus
17
+
18
+ RSpec.configure do |config|
19
+ config.around(:each) do |spec|
20
+ cached_config = Duststorm.config
21
+ spec.run
22
+ Duststorm.config = cached_config
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module HaveKeys
2
+ def have_keys_test(actual, keys)
3
+ @missing_keys = keys.flatten.map(&:to_sym) - actual.keys.flatten
4
+ @missing_keys.empty?
5
+ end
6
+
7
+ def have_keys_failure_message(actual)
8
+ "expected #{actual} to have keys #{@missing_keys}"
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ RSpec::Matchers.define :be_a_forecast_json do
2
+ include HaveKeys
3
+
4
+ keys = %w[
5
+ latitude
6
+ longitude
7
+ currently
8
+ hourly
9
+ daily
10
+ ]
11
+
12
+ match do |actual|
13
+ have_keys_test(actual, keys)
14
+ end
15
+
16
+ failure_message do |actual|
17
+ have_keys_failure_message(actual)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duststorm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Mcnamee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: typhoeus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Multiple weather API ruby wrapper
140
+ email:
141
+ - kevin@frothylabs.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - Gemfile
148
+ - LICENSE
149
+ - README.md
150
+ - Rakefile
151
+ - duststorm.gemspec
152
+ - lib/duststorm.rb
153
+ - lib/duststorm/attribute.rb
154
+ - lib/duststorm/attribute/coordinate.rb
155
+ - lib/duststorm/attribute/time.rb
156
+ - lib/duststorm/base.rb
157
+ - lib/duststorm/forecast.rb
158
+ - lib/duststorm/forecast/base.rb
159
+ - lib/duststorm/utils.rb
160
+ - lib/duststorm/utils/response_mapper.rb
161
+ - lib/duststorm/version.rb
162
+ - lib/duststorm/weather.rb
163
+ - lib/duststorm/weather/base.rb
164
+ - lib/duststorm/weather/current.rb
165
+ - lib/duststorm/weather/daily.rb
166
+ - lib/duststorm/weather/hourly.rb
167
+ - lib/duststorm/weather_api.rb
168
+ - lib/duststorm/weather_apis/base.rb
169
+ - lib/duststorm/weather_apis/forecast_io.rb
170
+ - lib/duststorm/weather_apis/wunderground.rb
171
+ - spec/cassettes/forecast_for_forecast_io.yml
172
+ - spec/cassettes/forecast_for_wunderground.yml
173
+ - spec/duststorm/base_spec.rb
174
+ - spec/duststorm/forecast/base_spec.rb
175
+ - spec/duststorm/forecast_spec.rb
176
+ - spec/duststorm/version_spec.rb
177
+ - spec/duststorm/weather/hourly_spec.rb
178
+ - spec/duststorm/weather_api_spec.rb
179
+ - spec/duststorm_spec.rb
180
+ - spec/features/weather_services_spec.rb
181
+ - spec/spec_helper.rb
182
+ - spec/support/have_keys.rb
183
+ - spec/support/matchers/be_a_forecast_json_matcher.rb
184
+ homepage: ''
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.1.11
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Multiple weather API ruby wrapper
208
+ test_files:
209
+ - spec/cassettes/forecast_for_forecast_io.yml
210
+ - spec/cassettes/forecast_for_wunderground.yml
211
+ - spec/duststorm/base_spec.rb
212
+ - spec/duststorm/forecast/base_spec.rb
213
+ - spec/duststorm/forecast_spec.rb
214
+ - spec/duststorm/version_spec.rb
215
+ - spec/duststorm/weather/hourly_spec.rb
216
+ - spec/duststorm/weather_api_spec.rb
217
+ - spec/duststorm_spec.rb
218
+ - spec/features/weather_services_spec.rb
219
+ - spec/spec_helper.rb
220
+ - spec/support/have_keys.rb
221
+ - spec/support/matchers/be_a_forecast_json_matcher.rb