forecast_io 1.2.0 → 2.0.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.
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0 (2013-07-05)
4
+
5
+ * `Forecast::IO` is now `ForecastIO`. Thanks [@pat](https://github.com/pat).
6
+
3
7
  ## 1.2.0 (2013-07-03)
4
8
 
5
9
  * You can now customize the default parameters sent on each call. Thanks [@pat](https://github.com/pat).
data/README.md CHANGED
@@ -23,7 +23,7 @@ require 'forecast_io'
23
23
  You will need to set your API key before you can make requests to the [forecast.io](https://developer.darkskyapp.com/docs/v2) API.
24
24
 
25
25
  ```ruby
26
- Forecast::IO.configure do |configuration|
26
+ ForecastIO.configure do |configuration|
27
27
  configuration.api_key = 'this-is-your-api-key'
28
28
  end
29
29
  ```
@@ -31,10 +31,10 @@ end
31
31
  Alternatively:
32
32
 
33
33
  ```ruby
34
- Forecast::IO.api_key = 'this-is-your-api-key'
34
+ ForecastIO.api_key = 'this-is-your-api-key'
35
35
  ```
36
36
 
37
- You can then make requests to the `Forecast::IO.forecast(latitude, longitude, options = {})` method.
37
+ You can then make requests to the `ForecastIO.forecast(latitude, longitude, options = {})` method.
38
38
 
39
39
  Valid options in the `options` hash are:
40
40
 
@@ -47,25 +47,25 @@ Valid options in the `options` hash are:
47
47
  Get the current forecast:
48
48
 
49
49
  ```ruby
50
- forecast = Forecast::IO.forecast(37.8267, -122.423)
50
+ forecast = ForecastIO.forecast(37.8267, -122.423)
51
51
  ```
52
52
 
53
53
  Get the current forecast at a given time:
54
54
 
55
55
  ```ruby
56
- forecast = Forecast::IO.forecast(37.8267, -122.423, time: Time.new(2013, 3, 11).to_i)
56
+ forecast = ForecastIO.forecast(37.8267, -122.423, time: Time.new(2013, 3, 11).to_i)
57
57
  ```
58
58
 
59
59
  Get the current forecast and use SI units:
60
60
 
61
61
  ```ruby
62
- forecast = Forecast::IO.forecast(37.8267, -122.423, params: { units: 'si' })
62
+ forecast = ForecastIO.forecast(37.8267, -122.423, params: { units: 'si' })
63
63
  ```
64
64
 
65
65
  The `forecast(...)` method will return a response that you can interact with in a more-friendly way, such as:
66
66
 
67
67
  ```ruby
68
- forecast = Forecast::IO.forecast(37.8267, -122.423)
68
+ forecast = ForecastIO.forecast(37.8267, -122.423)
69
69
  forecast.latitude
70
70
  forecast.longitude
71
71
  ```
@@ -91,7 +91,7 @@ Alternatively:
91
91
  ```ruby
92
92
  require 'typhoeus/adapters/faraday'
93
93
 
94
- Forecast::IO.connection = Faraday.new do |builder|
94
+ ForecastIO.connection = Faraday.new do |builder|
95
95
  builder.adapter :typhoeus
96
96
  end
97
97
  ```
@@ -99,11 +99,11 @@ end
99
99
  You can also customise the default parameters passed through on each API call:
100
100
 
101
101
  ```ruby
102
- Forecast::IO.default_params = {units: 'si'}
102
+ ForecastIO.default_params = {units: 'si'}
103
103
 
104
104
  # or
105
105
 
106
- Forecast::IO.configure do |configuration|
106
+ ForecastIO.configure do |configuration|
107
107
  configuration.default_params = {units: 'si'}
108
108
  end
109
109
  ```
@@ -5,7 +5,7 @@ require 'forecast_io/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "forecast_io"
8
- s.version = Forecast::IO::VERSION
8
+ s.version = ForecastIO::VERSION
9
9
  s.authors = ["David Czarnecki"]
10
10
  s.email = ["me@davidczarnecki.com"]
11
11
  s.homepage = "https://github.com/darkskyapp/forecast-ruby"
@@ -5,48 +5,46 @@ require 'hashie'
5
5
  require 'multi_json'
6
6
  require 'faraday'
7
7
 
8
- module Forecast
9
- module IO
10
- extend Configuration
11
-
12
- self.default_params = {}
13
-
14
- class << self
15
- # Retrieve the forecast for a given latitude and longitude.
16
- #
17
- # @param latitude [String] Latitude.
18
- # @param longitude [String] Longitude.
19
- # @param options [String] Optional parameters. Valid options are `:time` and `:params`.
20
- def forecast(latitude, longitude, options = {})
21
- forecast_url = "#{Forecast::IO.api_endpoint}/forecast/#{Forecast::IO.api_key}/#{latitude},#{longitude}"
22
- forecast_url += ",#{options[:time]}" if options[:time]
23
-
24
- forecast_response = get(forecast_url, options[:params])
25
-
26
- if forecast_response.success?
27
- return Hashie::Mash.new(MultiJson.load(forecast_response.body))
28
- end
29
- end
8
+ module ForecastIO
9
+ extend Configuration
30
10
 
31
- # Build or get an HTTP connection object.
32
- def connection
33
- @connection ||= Faraday.new
34
- end
11
+ self.default_params = {}
12
+
13
+ class << self
14
+ # Retrieve the forecast for a given latitude and longitude.
15
+ #
16
+ # @param latitude [String] Latitude.
17
+ # @param longitude [String] Longitude.
18
+ # @param options [String] Optional parameters. Valid options are `:time` and `:params`.
19
+ def forecast(latitude, longitude, options = {})
20
+ forecast_url = "#{ForecastIO.api_endpoint}/forecast/#{ForecastIO.api_key}/#{latitude},#{longitude}"
21
+ forecast_url += ",#{options[:time]}" if options[:time]
35
22
 
36
- # Set an HTTP connection object.
37
- #
38
- # @param connection Connection object to be used.
39
- def connection=(connection)
40
- @connection = connection
23
+ forecast_response = get(forecast_url, options[:params])
24
+
25
+ if forecast_response.success?
26
+ return Hashie::Mash.new(MultiJson.load(forecast_response.body))
41
27
  end
28
+ end
42
29
 
43
- private
30
+ # Build or get an HTTP connection object.
31
+ def connection
32
+ @connection ||= Faraday.new
33
+ end
44
34
 
45
- def get(path, params = {})
46
- params = Forecast::IO.default_params.merge(params || {})
35
+ # Set an HTTP connection object.
36
+ #
37
+ # @param connection Connection object to be used.
38
+ def connection=(connection)
39
+ @connection = connection
40
+ end
47
41
 
48
- connection.get(path, params)
49
- end
42
+ private
43
+
44
+ def get(path, params = {})
45
+ params = ForecastIO.default_params.merge(params || {})
46
+
47
+ connection.get(path, params)
50
48
  end
51
49
  end
52
50
  end
@@ -1,38 +1,36 @@
1
- module Forecast
2
- module IO
3
- module Configuration
4
- # Default API endpoint
5
- DEFAULT_FORECAST_IO_API_ENDPOINT = 'https://api.forecast.io'
1
+ module ForecastIO
2
+ module Configuration
3
+ # Default API endpoint
4
+ DEFAULT_FORECAST_IO_API_ENDPOINT = 'https://api.forecast.io'
6
5
 
7
- # Forecast API endpoint
8
- attr_writer :api_endpoint
6
+ # Forecast API endpoint
7
+ attr_writer :api_endpoint
9
8
 
10
- # API key
11
- attr_writer :api_key
9
+ # API key
10
+ attr_writer :api_key
12
11
 
13
- # Default parameters
14
- attr_accessor :default_params
12
+ # Default parameters
13
+ attr_accessor :default_params
15
14
 
16
- # Yield self to be able to configure Forecast::IO with block-style configuration.
17
- #
18
- # Example:
19
- #
20
- # Forecast::IO.configure do |configuration|
21
- # configuration.api_key = 'this-is-your-api-key'
22
- # end
23
- def configure
24
- yield self
25
- end
15
+ # Yield self to be able to configure ForecastIO with block-style configuration.
16
+ #
17
+ # Example:
18
+ #
19
+ # ForecastIO.configure do |configuration|
20
+ # configuration.api_key = 'this-is-your-api-key'
21
+ # end
22
+ def configure
23
+ yield self
24
+ end
26
25
 
27
- # API endpoint
28
- def api_endpoint
29
- @api_endpoint ||= DEFAULT_FORECAST_IO_API_ENDPOINT
30
- end
26
+ # API endpoint
27
+ def api_endpoint
28
+ @api_endpoint ||= DEFAULT_FORECAST_IO_API_ENDPOINT
29
+ end
31
30
 
32
- # API key
33
- def api_key
34
- @api_key
35
- end
31
+ # API key
32
+ def api_key
33
+ @api_key
36
34
  end
37
35
  end
38
36
  end
@@ -1,6 +1,3 @@
1
- module Forecast
2
- module IO
3
- # Current Forecast::IO version
4
- VERSION = '1.2.0'
5
- end
1
+ module ForecastIO
2
+ VERSION = '2.0.0'
6
3
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Forecast::IO::Configuration do
3
+ describe ForecastIO::Configuration do
4
4
  describe '.configure' do
5
5
  it 'should have default attributes' do
6
- Forecast::IO.configure do |configuration|
7
- configuration.api_endpoint.should eql(Forecast::IO::Configuration::DEFAULT_FORECAST_IO_API_ENDPOINT)
6
+ ForecastIO.configure do |configuration|
7
+ configuration.api_endpoint.should eql(ForecastIO::Configuration::DEFAULT_FORECAST_IO_API_ENDPOINT)
8
8
  configuration.api_key.should be_nil
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,17 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Forecast::IO do
3
+ describe ForecastIO do
4
4
  describe '.default_params' do
5
5
  it "defaults to an empty hash" do
6
- Forecast::IO.default_params.should == {}
6
+ ForecastIO.default_params.should == {}
7
7
  end
8
8
  end
9
9
 
10
10
  describe '.forecast' do
11
+ before :each do
12
+ ForecastIO.api_key = 'this-is-an-api-key'
13
+ end
14
+
11
15
  it 'should return a forecast for a given latitude, longitude' do
12
16
  VCR.use_cassette('forecast_for_latitude_longitude', record: :once) do
13
- Forecast::IO.api_key = 'this-is-an-api-key'
14
- forecast = Forecast::IO.forecast('37.8267','-122.423')
17
+ forecast = ForecastIO.forecast('37.8267','-122.423')
15
18
  forecast.should_not be_nil
16
19
  forecast.latitude.should == 37.8267
17
20
  forecast.longitude.should == -122.423
@@ -22,8 +25,7 @@ describe Forecast::IO do
22
25
 
23
26
  it 'should return a forecast for a given latitude, longitude and time' do
24
27
  VCR.use_cassette('forecast_for_latitude_longitude_and_time') do
25
- Forecast::IO.api_key = 'this-is-an-api-key'
26
- forecast = Forecast::IO.forecast('37.8267','-122.423', time: Time.utc(2013, 3, 11, 4).to_i)
28
+ forecast = ForecastIO.forecast('37.8267','-122.423', time: Time.utc(2013, 3, 11, 4).to_i)
27
29
  forecast.should_not be_nil
28
30
  forecast.latitude.should == 37.8267
29
31
  forecast.longitude.should == -122.423
@@ -34,8 +36,7 @@ describe Forecast::IO do
34
36
 
35
37
  it 'should return a forecast for a given latitude, longitude and query params' do
36
38
  VCR.use_cassette('forecast_for_latitude_longitude_and_query_params') do
37
- Forecast::IO.api_key = 'this-is-an-api-key'
38
- forecast = Forecast::IO.forecast('37.8267','-122.423', params: {units: 'si'})
39
+ forecast = ForecastIO.forecast('37.8267','-122.423', params: {units: 'si'})
39
40
  forecast.should_not be_nil
40
41
  forecast.latitude.should == 37.8267
41
42
  forecast.longitude.should == -122.423
@@ -51,60 +52,60 @@ describe Forecast::IO do
51
52
  before :each do
52
53
  stub_const 'Faraday', stub(new: faraday)
53
54
 
54
- Forecast::IO.stub api_key: 'abc123', connection: faraday
55
+ ForecastIO.stub(api_key: 'abc123', connection: faraday)
55
56
  end
56
57
 
57
58
  context 'without default parameters' do
58
59
  before :each do
59
- Forecast::IO.stub default_params: {}
60
+ ForecastIO.stub(default_params: {})
60
61
  end
61
62
 
62
63
  it "sends through a standard request" do
63
64
  faraday.should_receive(:get).with(
64
65
  'https://api.forecast.io/forecast/abc123/1.2,3.4', {}
65
- ).and_return response
66
+ ).and_return(response)
66
67
 
67
- Forecast::IO.forecast 1.2, 3.4
68
+ ForecastIO.forecast(1.2, 3.4)
68
69
  end
69
70
 
70
71
  it "sends through provided parameters" do
71
72
  faraday.should_receive(:get).with(
72
73
  'https://api.forecast.io/forecast/abc123/1.2,3.4', {units: 'si'}
73
- ).and_return response
74
+ ).and_return(response)
74
75
 
75
- Forecast::IO.forecast 1.2, 3.4, params: {units: 'si'}
76
+ ForecastIO.forecast(1.2, 3.4, params: {units: 'si'})
76
77
  end
77
78
  end
78
79
 
79
80
  context 'with default parameters' do
80
81
  before :each do
81
- Forecast::IO.stub default_params: {units: 'si'}
82
+ ForecastIO.stub(default_params: {units: 'si'})
82
83
  end
83
84
 
84
85
  it "sends through the default parameters" do
85
86
  faraday.should_receive(:get).with(
86
87
  'https://api.forecast.io/forecast/abc123/1.2,3.4', {units: 'si'}
87
- ).and_return response
88
+ ).and_return(response)
88
89
 
89
- Forecast::IO.forecast 1.2, 3.4
90
+ ForecastIO.forecast(1.2, 3.4)
90
91
  end
91
92
 
92
93
  it "sends through the merged parameters" do
93
94
  faraday.should_receive(:get).with(
94
95
  'https://api.forecast.io/forecast/abc123/1.2,3.4',
95
96
  {units: 'si', exclude: 'daily'}
96
- ).and_return response
97
+ ).and_return(response)
97
98
 
98
- Forecast::IO.forecast 1.2, 3.4, params: {exclude: 'daily'}
99
+ ForecastIO.forecast(1.2, 3.4, params: {exclude: 'daily'})
99
100
  end
100
101
 
101
102
  it "overwrites default parameters when appropriate" do
102
103
  faraday.should_receive(:get).with(
103
104
  'https://api.forecast.io/forecast/abc123/1.2,3.4',
104
105
  {units: 'imperial'}
105
- ).and_return response
106
+ ).and_return(response)
106
107
 
107
- Forecast::IO.forecast 1.2, 3.4, params: {units: 'imperial'}
108
+ ForecastIO.forecast(1.2, 3.4, params: {units: 'imperial'})
108
109
  end
109
110
  end
110
111
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Forecast::IO::VERSION' do
3
+ describe 'ForecastIO::VERSION' do
4
4
  it 'should be the correct version' do
5
- Forecast::IO::VERSION.should == '1.2.0'
5
+ ForecastIO::VERSION.should == '2.0.0'
6
6
  end
7
- end
7
+ end
@@ -16,6 +16,6 @@ Faraday.default_adapter = :typhoeus
16
16
 
17
17
  RSpec.configure do |config|
18
18
  config.before(:each) do
19
- Forecast::IO.api_key = nil
19
+ ForecastIO.api_key = nil
20
20
  end
21
21
  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.2.0
4
+ version: 2.0.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-07-03 00:00:00.000000000 Z
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 2422846416094696437
167
+ hash: -4308199890416542600
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: 2422846416094696437
176
+ hash: -4308199890416542600
177
177
  requirements: []
178
178
  rubyforge_project: forecast_io
179
179
  rubygems_version: 1.8.25