forecast_io 1.0.0 → 1.1.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 +4 -0
- data/README.md +31 -6
- data/forecast_io.gemspec +2 -1
- data/lib/forecast_io.rb +15 -3
- data/lib/forecast_io/version.rb +1 -1
- data/spec/cassettes/forecast_for_latitude_longitide_and_query_params.yml +1 -1
- data/spec/forecast_io/forecast_io_spec.rb +3 -3
- data/spec/forecast_io/version_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +21 -5
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -38,39 +38,64 @@ You can then make requests to the `Forecast::IO.forecast(latitude, longitide, op
|
|
38
38
|
|
39
39
|
Valid options in the `options` hash are:
|
40
40
|
|
41
|
-
* `:time` -
|
41
|
+
* `:time` - Unix time in seconds.
|
42
42
|
* `:params` - Query parameters that can contain the following:
|
43
43
|
* `:jsonp` - JSONP callback.
|
44
|
-
* `:
|
44
|
+
* `:units` - Return the API response in SI units, rather than the default Imperial units.
|
45
|
+
* `:exclude` - "Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space. [blocks] should be a comma-delimeted list (without spaces) of any of the following: currently, minutely, hourly, daily, alerts, flags." (via [v2 docs](https://developer.forecast.io/docs/v2#changelog))
|
45
46
|
|
46
47
|
Get the current forecast:
|
47
48
|
|
48
49
|
```ruby
|
49
|
-
forecast = Forecast::IO.forecast(
|
50
|
+
forecast = Forecast::IO.forecast(37.8267, -122.423)
|
50
51
|
```
|
51
52
|
|
52
53
|
Get the current forecast at a given time:
|
53
54
|
|
54
55
|
```ruby
|
55
|
-
forecast = Forecast::IO.forecast(
|
56
|
+
forecast = Forecast::IO.forecast(37.8267, -122.423, time: Time.new(2013, 3, 11).to_i)
|
56
57
|
```
|
57
58
|
|
58
59
|
Get the current forecast and use SI units:
|
59
60
|
|
60
61
|
```ruby
|
61
|
-
forecast = Forecast::IO.forecast(
|
62
|
+
forecast = Forecast::IO.forecast(37.8267, -122.423, params: { units: 'si' })
|
62
63
|
```
|
63
64
|
|
64
65
|
The `forecast(...)` method will return a response that you can interact with in a more-friendly way, such as:
|
65
66
|
|
66
67
|
```ruby
|
67
|
-
forecast = Forecast::IO.forecast(
|
68
|
+
forecast = Forecast::IO.forecast(37.8267, -122.423)
|
68
69
|
forecast.latitude
|
69
70
|
forecast.longitude
|
70
71
|
```
|
71
72
|
|
72
73
|
Please refer to the [forecast.io](https://developer.darkskyapp.com/docs/v2) API documentation for more information on the full response properties.
|
73
74
|
|
75
|
+
The HTTP requests are made with [Faraday](https://github.com/lostisland/faraday), which uses `Net::HTTP` by default. Changing the adapter is easy. We will use typhoeus as an example.
|
76
|
+
|
77
|
+
Make sure to include the typhoeus gem in your `Gemfile`:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
gem 'typhoeus'
|
81
|
+
```
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
require 'typhoeus/adapters/faraday'
|
85
|
+
|
86
|
+
Faraday.default_adapter = :typhoeus
|
87
|
+
```
|
88
|
+
|
89
|
+
Alternatively:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'typhoeus/adapters/faraday'
|
93
|
+
|
94
|
+
Forecast::IO.connection = Faraday.new do |builder|
|
95
|
+
builder.adapter :typhoeus
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
74
99
|
## Contributing to forecast_io
|
75
100
|
|
76
101
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/forecast_io.gemspec
CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency('
|
22
|
+
s.add_dependency('faraday')
|
23
23
|
s.add_dependency('multi_json')
|
24
24
|
s.add_dependency('hashie')
|
25
25
|
|
26
26
|
s.add_development_dependency('rake')
|
27
27
|
s.add_development_dependency('rspec')
|
28
28
|
s.add_development_dependency('vcr')
|
29
|
+
s.add_development_dependency('typhoeus')
|
29
30
|
end
|
data/lib/forecast_io.rb
CHANGED
@@ -3,7 +3,7 @@ require 'forecast_io/version'
|
|
3
3
|
|
4
4
|
require 'hashie'
|
5
5
|
require 'multi_json'
|
6
|
-
require '
|
6
|
+
require 'faraday'
|
7
7
|
|
8
8
|
module Forecast
|
9
9
|
module IO
|
@@ -20,15 +20,27 @@ module Forecast
|
|
20
20
|
forecast_url += ",#{options[:time]}" if options[:time]
|
21
21
|
|
22
22
|
forecast_response = if options[:params]
|
23
|
-
|
23
|
+
connection.get(forecast_url, options[:params])
|
24
24
|
else
|
25
|
-
|
25
|
+
connection.get(forecast_url)
|
26
26
|
end
|
27
27
|
|
28
28
|
if forecast_response.success?
|
29
29
|
return Hashie::Mash.new(MultiJson.load(forecast_response.body))
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
# Build or get an HTTP connection object.
|
34
|
+
def connection
|
35
|
+
@connection ||= Faraday.new
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set an HTTP connection object.
|
39
|
+
#
|
40
|
+
# @param connection Connection object to be used.
|
41
|
+
def connection=(connection)
|
42
|
+
@connection = connection
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
data/lib/forecast_io/version.rb
CHANGED
@@ -17,7 +17,7 @@ describe Forecast::IO do
|
|
17
17
|
it 'should return a forecast for a given latitude, longitude and time' do
|
18
18
|
VCR.use_cassette('forecast_for_latitude_longitide_and_time') do
|
19
19
|
Forecast::IO.api_key = 'this-is-an-api-key'
|
20
|
-
forecast = Forecast::IO.forecast('37.8267','-122.423', time: Time.
|
20
|
+
forecast = Forecast::IO.forecast('37.8267','-122.423', time: Time.utc(2013, 3, 11, 4).to_i)
|
21
21
|
forecast.should_not be_nil
|
22
22
|
forecast.latitude.should == 37.8267
|
23
23
|
forecast.longitude.should == -122.423
|
@@ -29,7 +29,7 @@ describe Forecast::IO do
|
|
29
29
|
it 'should return a forecast for a given latitude, longitude and query params' do
|
30
30
|
VCR.use_cassette('forecast_for_latitude_longitide_and_query_params') do
|
31
31
|
Forecast::IO.api_key = 'this-is-an-api-key'
|
32
|
-
forecast = Forecast::IO.forecast('37.8267','-122.423', params: {
|
32
|
+
forecast = Forecast::IO.forecast('37.8267','-122.423', params: {units: 'si'})
|
33
33
|
forecast.should_not be_nil
|
34
34
|
forecast.latitude.should == 37.8267
|
35
35
|
forecast.longitude.should == -122.423
|
@@ -38,4 +38,4 @@ describe Forecast::IO do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require 'forecast_io'
|
|
4
4
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
5
5
|
|
6
6
|
require 'vcr'
|
7
|
+
require 'typhoeus/adapters/faraday'
|
7
8
|
|
8
9
|
VCR.configure do |c|
|
9
10
|
c.cassette_library_dir = 'spec/cassettes'
|
@@ -11,6 +12,8 @@ VCR.configure do |c|
|
|
11
12
|
c.allow_http_connections_when_no_cassette = false
|
12
13
|
end
|
13
14
|
|
15
|
+
Faraday.default_adapter = :typhoeus
|
16
|
+
|
14
17
|
RSpec.configure do |config|
|
15
18
|
config.before(:each) do
|
16
19
|
Forecast::IO.api_key = nil
|
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.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: faraday
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: typhoeus
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: forecast.io API wrapper in Ruby
|
111
127
|
email:
|
112
128
|
- me@davidczarnecki.com
|
@@ -148,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
164
|
version: '0'
|
149
165
|
segments:
|
150
166
|
- 0
|
151
|
-
hash:
|
167
|
+
hash: -176553111951158824
|
152
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
169
|
none: false
|
154
170
|
requirements:
|
@@ -157,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
173
|
version: '0'
|
158
174
|
segments:
|
159
175
|
- 0
|
160
|
-
hash:
|
176
|
+
hash: -176553111951158824
|
161
177
|
requirements: []
|
162
178
|
rubyforge_project: forecast_io
|
163
179
|
rubygems_version: 1.8.25
|