forecast_io 1.1.0 → 1.2.0
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.
- data/CHANGELOG.md +6 -2
- data/README.md +13 -1
- data/lib/forecast_io.rb +11 -5
- data/lib/forecast_io/configuration.rb +4 -1
- data/lib/forecast_io/version.rb +1 -1
- data/spec/cassettes/{forecast_for_latitude_longitide.yml → forecast_for_latitude_longitude.yml} +0 -0
- data/spec/cassettes/{forecast_for_latitude_longitide_and_query_params.yml → forecast_for_latitude_longitude_and_query_params.yml} +0 -0
- data/spec/cassettes/{forecast_for_latitude_longitide_and_time.yml → forecast_for_latitude_longitude_and_time.yml} +0 -0
- data/spec/forecast_io/forecast_io_spec.rb +74 -3
- data/spec/forecast_io/version_spec.rb +1 -1
- metadata +10 -10
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.2.0 (2013-07-03)
|
4
|
+
|
5
|
+
* You can now customize the default parameters sent on each call. Thanks [@pat](https://github.com/pat).
|
6
|
+
|
7
|
+
## 1.1.0 (2013-04-04)
|
4
8
|
|
5
9
|
* Gem now uses [Faraday](https://github.com/lostisland/faraday) to allow for swapping of the underlying HTTP library. Thanks [@norbert](https://github.com/norbert).
|
6
10
|
|
7
|
-
## 1.0.0
|
11
|
+
## 1.0.0 (2013-03-27)
|
8
12
|
|
9
13
|
* Initial release
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Alternatively:
|
|
34
34
|
Forecast::IO.api_key = 'this-is-your-api-key'
|
35
35
|
```
|
36
36
|
|
37
|
-
You can then make requests to the `Forecast::IO.forecast(latitude,
|
37
|
+
You can then make requests to the `Forecast::IO.forecast(latitude, longitude, options = {})` method.
|
38
38
|
|
39
39
|
Valid options in the `options` hash are:
|
40
40
|
|
@@ -96,6 +96,18 @@ Forecast::IO.connection = Faraday.new do |builder|
|
|
96
96
|
end
|
97
97
|
```
|
98
98
|
|
99
|
+
You can also customise the default parameters passed through on each API call:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
Forecast::IO.default_params = {units: 'si'}
|
103
|
+
|
104
|
+
# or
|
105
|
+
|
106
|
+
Forecast::IO.configure do |configuration|
|
107
|
+
configuration.default_params = {units: 'si'}
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
99
111
|
## Contributing to forecast_io
|
100
112
|
|
101
113
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/lib/forecast_io.rb
CHANGED
@@ -9,6 +9,8 @@ module Forecast
|
|
9
9
|
module IO
|
10
10
|
extend Configuration
|
11
11
|
|
12
|
+
self.default_params = {}
|
13
|
+
|
12
14
|
class << self
|
13
15
|
# Retrieve the forecast for a given latitude and longitude.
|
14
16
|
#
|
@@ -19,11 +21,7 @@ module Forecast
|
|
19
21
|
forecast_url = "#{Forecast::IO.api_endpoint}/forecast/#{Forecast::IO.api_key}/#{latitude},#{longitude}"
|
20
22
|
forecast_url += ",#{options[:time]}" if options[:time]
|
21
23
|
|
22
|
-
forecast_response =
|
23
|
-
connection.get(forecast_url, options[:params])
|
24
|
-
else
|
25
|
-
connection.get(forecast_url)
|
26
|
-
end
|
24
|
+
forecast_response = get(forecast_url, options[:params])
|
27
25
|
|
28
26
|
if forecast_response.success?
|
29
27
|
return Hashie::Mash.new(MultiJson.load(forecast_response.body))
|
@@ -41,6 +39,14 @@ module Forecast
|
|
41
39
|
def connection=(connection)
|
42
40
|
@connection = connection
|
43
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def get(path, params = {})
|
46
|
+
params = Forecast::IO.default_params.merge(params || {})
|
47
|
+
|
48
|
+
connection.get(path, params)
|
49
|
+
end
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
@@ -10,6 +10,9 @@ module Forecast
|
|
10
10
|
# API key
|
11
11
|
attr_writer :api_key
|
12
12
|
|
13
|
+
# Default parameters
|
14
|
+
attr_accessor :default_params
|
15
|
+
|
13
16
|
# Yield self to be able to configure Forecast::IO with block-style configuration.
|
14
17
|
#
|
15
18
|
# Example:
|
@@ -32,4 +35,4 @@ module Forecast
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
35
|
-
end
|
38
|
+
end
|
data/lib/forecast_io/version.rb
CHANGED
data/spec/cassettes/{forecast_for_latitude_longitide.yml → forecast_for_latitude_longitude.yml}
RENAMED
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Forecast::IO do
|
4
|
+
describe '.default_params' do
|
5
|
+
it "defaults to an empty hash" do
|
6
|
+
Forecast::IO.default_params.should == {}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe '.forecast' do
|
5
11
|
it 'should return a forecast for a given latitude, longitude' do
|
6
|
-
VCR.use_cassette('
|
12
|
+
VCR.use_cassette('forecast_for_latitude_longitude', record: :once) do
|
7
13
|
Forecast::IO.api_key = 'this-is-an-api-key'
|
8
14
|
forecast = Forecast::IO.forecast('37.8267','-122.423')
|
9
15
|
forecast.should_not be_nil
|
@@ -15,7 +21,7 @@ describe Forecast::IO do
|
|
15
21
|
end
|
16
22
|
|
17
23
|
it 'should return a forecast for a given latitude, longitude and time' do
|
18
|
-
VCR.use_cassette('
|
24
|
+
VCR.use_cassette('forecast_for_latitude_longitude_and_time') do
|
19
25
|
Forecast::IO.api_key = 'this-is-an-api-key'
|
20
26
|
forecast = Forecast::IO.forecast('37.8267','-122.423', time: Time.utc(2013, 3, 11, 4).to_i)
|
21
27
|
forecast.should_not be_nil
|
@@ -27,7 +33,7 @@ describe Forecast::IO do
|
|
27
33
|
end
|
28
34
|
|
29
35
|
it 'should return a forecast for a given latitude, longitude and query params' do
|
30
|
-
VCR.use_cassette('
|
36
|
+
VCR.use_cassette('forecast_for_latitude_longitude_and_query_params') do
|
31
37
|
Forecast::IO.api_key = 'this-is-an-api-key'
|
32
38
|
forecast = Forecast::IO.forecast('37.8267','-122.423', params: {units: 'si'})
|
33
39
|
forecast.should_not be_nil
|
@@ -37,5 +43,70 @@ describe Forecast::IO do
|
|
37
43
|
forecast.alerts.should be_nil
|
38
44
|
end
|
39
45
|
end
|
46
|
+
|
47
|
+
context 'unit tests' do
|
48
|
+
let(:faraday) { double 'Faraday', get: response }
|
49
|
+
let(:response) { double 'Response', success?: true, body: '{}' }
|
50
|
+
|
51
|
+
before :each do
|
52
|
+
stub_const 'Faraday', stub(new: faraday)
|
53
|
+
|
54
|
+
Forecast::IO.stub api_key: 'abc123', connection: faraday
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'without default parameters' do
|
58
|
+
before :each do
|
59
|
+
Forecast::IO.stub default_params: {}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sends through a standard request" do
|
63
|
+
faraday.should_receive(:get).with(
|
64
|
+
'https://api.forecast.io/forecast/abc123/1.2,3.4', {}
|
65
|
+
).and_return response
|
66
|
+
|
67
|
+
Forecast::IO.forecast 1.2, 3.4
|
68
|
+
end
|
69
|
+
|
70
|
+
it "sends through provided parameters" do
|
71
|
+
faraday.should_receive(:get).with(
|
72
|
+
'https://api.forecast.io/forecast/abc123/1.2,3.4', {units: 'si'}
|
73
|
+
).and_return response
|
74
|
+
|
75
|
+
Forecast::IO.forecast 1.2, 3.4, params: {units: 'si'}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with default parameters' do
|
80
|
+
before :each do
|
81
|
+
Forecast::IO.stub default_params: {units: 'si'}
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sends through the default parameters" do
|
85
|
+
faraday.should_receive(:get).with(
|
86
|
+
'https://api.forecast.io/forecast/abc123/1.2,3.4', {units: 'si'}
|
87
|
+
).and_return response
|
88
|
+
|
89
|
+
Forecast::IO.forecast 1.2, 3.4
|
90
|
+
end
|
91
|
+
|
92
|
+
it "sends through the merged parameters" do
|
93
|
+
faraday.should_receive(:get).with(
|
94
|
+
'https://api.forecast.io/forecast/abc123/1.2,3.4',
|
95
|
+
{units: 'si', exclude: 'daily'}
|
96
|
+
).and_return response
|
97
|
+
|
98
|
+
Forecast::IO.forecast 1.2, 3.4, params: {exclude: 'daily'}
|
99
|
+
end
|
100
|
+
|
101
|
+
it "overwrites default parameters when appropriate" do
|
102
|
+
faraday.should_receive(:get).with(
|
103
|
+
'https://api.forecast.io/forecast/abc123/1.2,3.4',
|
104
|
+
{units: 'imperial'}
|
105
|
+
).and_return response
|
106
|
+
|
107
|
+
Forecast::IO.forecast 1.2, 3.4, params: {units: 'imperial'}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
40
111
|
end
|
41
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forecast_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -143,9 +143,9 @@ files:
|
|
143
143
|
- lib/forecast_io/configuration.rb
|
144
144
|
- lib/forecast_io/version.rb
|
145
145
|
- spec/cassettes/.keep
|
146
|
-
- spec/cassettes/
|
147
|
-
- spec/cassettes/
|
148
|
-
- spec/cassettes/
|
146
|
+
- spec/cassettes/forecast_for_latitude_longitude.yml
|
147
|
+
- spec/cassettes/forecast_for_latitude_longitude_and_query_params.yml
|
148
|
+
- spec/cassettes/forecast_for_latitude_longitude_and_time.yml
|
149
149
|
- spec/forecast_io/configuration_spec.rb
|
150
150
|
- spec/forecast_io/forecast_io_spec.rb
|
151
151
|
- spec/forecast_io/version_spec.rb
|
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
segments:
|
166
166
|
- 0
|
167
|
-
hash:
|
167
|
+
hash: 2422846416094696437
|
168
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
169
|
none: false
|
170
170
|
requirements:
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
segments:
|
175
175
|
- 0
|
176
|
-
hash:
|
176
|
+
hash: 2422846416094696437
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project: forecast_io
|
179
179
|
rubygems_version: 1.8.25
|
@@ -182,9 +182,9 @@ specification_version: 3
|
|
182
182
|
summary: forecast.io API wrapper in Ruby
|
183
183
|
test_files:
|
184
184
|
- spec/cassettes/.keep
|
185
|
-
- spec/cassettes/
|
186
|
-
- spec/cassettes/
|
187
|
-
- spec/cassettes/
|
185
|
+
- spec/cassettes/forecast_for_latitude_longitude.yml
|
186
|
+
- spec/cassettes/forecast_for_latitude_longitude_and_query_params.yml
|
187
|
+
- spec/cassettes/forecast_for_latitude_longitude_and_time.yml
|
188
188
|
- spec/forecast_io/configuration_spec.rb
|
189
189
|
- spec/forecast_io/forecast_io_spec.rb
|
190
190
|
- spec/forecast_io/version_spec.rb
|