darksky 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.3
4
+
5
+ * Added `interesting` API endpoint to return a list of interesting storms happening right now.
6
+ * Fixed bug in `precipitation` API endpoint where multiple locations were not correctly passed to the API.
7
+
3
8
  ## 1.0.2
4
9
 
5
10
  * Removed default to disable SSL peer verification now that the DarkSky API server has a signed certificate.
@@ -17,8 +17,15 @@ gem 'darksky'
17
17
 
18
18
  ```ruby
19
19
  darksky = Darksky::API.new('d41d8cd98f00b204e9800998ecf8427e')
20
+
21
+ # Returns a forecast for the next hour at a given location.
20
22
  forecast = darksky.forecast('42.7243','-73.6927')
23
+
24
+ # Returns forecasts for a collection of arbitrary points.
21
25
  precipitation = darksky.precipitation(['42.7','-73.6',1325607100,'42.0','-73.0',1325607791])
26
+
27
+ # Returns a list of interesting storms happening right now.
28
+ interesting_storms = darksky.interesting
22
29
  ```
23
30
 
24
31
  ## Contributing to darksky
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "darksky"
7
7
  s.version = Darksky::VERSION
8
8
  s.authors = ["David Czarnecki"]
9
- s.email = ["me@davidczarnecki"]
9
+ s.email = ["me@davidczarnecki.com"]
10
10
  s.homepage = "https://github.com/czarneckid/darksky"
11
11
  s.summary = %q{Ruby gem for retrieving data from the Dark Sky API}
12
12
  s.description = %q{Ruby gem for retrieving data from the Dark Sky API}
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_development_dependency('rake')
24
24
  s.add_development_dependency('rspec')
25
+ s.add_development_dependency('vcr')
25
26
  end
@@ -30,8 +30,20 @@ module Darksky
30
30
  # @param option [Hash] (Optional) Options to be passed to the Typhoeus::Request
31
31
  def precipitation(latitudes_longitudes_times, options = {})
32
32
  return if latitudes_longitudes_times.size % 3 != 0
33
- response = Typhoeus::Request.get("#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{latitudes_longitudes_times.join(',')}", DEFAULT_OPTIONS.dup.merge(options))
33
+ params = []
34
+ latitudes_longitudes_times.each_slice(3) do |data|
35
+ params << data.join(',')
36
+ end
37
+ response = Typhoeus::Request.get("#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{params.join(';')}", DEFAULT_OPTIONS.dup.merge(options))
34
38
  JSON.parse(response.body) if response.code == 200
35
39
  end
40
+
41
+ # Returns a list of interesting storms happening right now.
42
+ #
43
+ # @param option [Hash] (Optional) Options to be passed to the Typhoeus::Request
44
+ def interesting(options = {})
45
+ response = Typhoeus::Request.get("#{DARKSKY_API_URL}/interesting/#{@api_key}", DEFAULT_OPTIONS.dup.merge(options))
46
+ JSON.parse(response.body) if response.code == 200
47
+ end
36
48
  end
37
49
  end
@@ -1,3 +1,3 @@
1
1
  module Darksky
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -0,0 +1,28 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.darkskyapp.com/v1/forecast/this-is-your-dark-sky-api-key/42.7243,-73.6927
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ X-Powered-By:
16
+ - Express
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '5911'
21
+ Connection:
22
+ - keep-alive
23
+ body:
24
+ encoding: ASCII-8BIT
25
+ string: ! '{"isPrecipitating":false,"minutesUntilChange":0,"currentSummary":"clear","hourSummary":"clear","radarStation":"enx","hourPrecipitation":[{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857375},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857435},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857495},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857555},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857615},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857675},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857735},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857795},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857855},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857915},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331857975},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858035},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858095},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858155},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858215},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858275},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858335},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858395},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858455},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858515},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858575},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858635},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858695},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858755},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858815},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858875},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858935},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331858995},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859055},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859115},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859175},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859235},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859295},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859355},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859415},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859475},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859535},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859595},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859655},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859715},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859775},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859835},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859895},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331859955},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860015},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860075},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860135},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860195},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860255},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860315},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860375},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860435},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860495},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860555},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860615},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860675},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860735},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860795},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860855},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1331860915}],"dayPrecipitation":[{"time":1331769600,"probability":0.69,"type":"rain"},{"time":1331773200,"probability":0.37,"type":"rain"},{"time":1331776800,"probability":0.28,"type":"rain"},{"time":1331780400,"probability":0.09,"type":"rain"},{"time":1331784000,"probability":0.06,"type":"rain"},{"time":1331787600,"probability":0.04,"type":"rain"},{"time":1331791200,"probability":0.04,"type":"rain"},{"time":1331794800,"probability":0.04,"type":"rain"},{"time":1331798400,"probability":0.07,"type":"rain"},{"time":1331802000,"probability":0.09,"type":"rain"},{"time":1331805600,"probability":0.12,"type":"rain"},{"time":1331809200,"probability":0.15,"type":"rain"},{"time":1331812800,"probability":0.17,"type":"rain"},{"time":1331816400,"probability":0.2,"type":"rain"},{"time":1331820000,"probability":0.22,"type":"rain"},{"time":1331823600,"probability":0.25,"type":"rain"},{"time":1331827200,"probability":0.16,"type":"rain"},{"time":1331830800,"probability":0.12,"type":"rain"},{"time":1331834400,"probability":0.06,"type":"rain"},{"time":1331838000,"probability":0.04,"type":"rain"},{"time":1331841600,"probability":0.01,"type":"rain"},{"time":1331845200,"probability":0,"type":"rain"},{"time":1331848800,"probability":0,"type":"rain"},{"time":1331852400,"probability":0,"type":"rain"},{"time":1331856000,"probability":0,"type":"rain"}]}'
26
+ http_version: '1.1'
27
+ recorded_at: Fri, 16 Mar 2012 00:22:55 GMT
28
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.darkskyapp.com/v1/interesting/this-is-your-dark-sky-api-key
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ X-Powered-By:
16
+ - Express
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '1213'
21
+ Connection:
22
+ - keep-alive
23
+ body:
24
+ encoding: ASCII-8BIT
25
+ string: ! '{"storms":[{"station":"gwx","intensity":59.1176,"city":"Triana, AL","longitude":-86.75493150419186,"latitude":34.641395125358194},{"station":"dtx","intensity":57.9412,"city":"South
26
+ Monroe, MI","longitude":-83.39335852861447,"latitude":41.86838558543463},{"station":"htx","intensity":56.4706,"city":"Huntsville,
27
+ AL","longitude":-86.62052879383518,"latitude":34.79127010512976},{"station":"jkl","intensity":56.1765,"city":"Manchester,
28
+ KY","longitude":-83.749418868936,"latitude":37.05544557347635},{"station":"iwx","intensity":56.1765,"city":"Bass
29
+ Lake, IN","longitude":-86.55524444156121,"latitude":41.19456019130322},{"station":"pah","intensity":56.1765,"city":"Centerville,
30
+ MO","longitude":-91.05466740454301,"latitude":37.54925976072387},{"station":"lot","intensity":55.5882,"city":"Bass
31
+ Lake, IN","longitude":-86.63659365658056,"latitude":41.211492393559716},{"station":"ilx","intensity":55,"city":"Winchester,
32
+ IL","longitude":-90.42692738243768,"latitude":39.68433565620716},{"station":"lsx","intensity":55,"city":"Centerville,
33
+ MO","longitude":-91.07445695965303,"latitude":37.37996424972698},{"station":"sgf","intensity":54.7059,"city":"Salem,
34
+ MO","longitude":-91.53280101446386,"latitude":37.788012812361}]}'
35
+ http_version: '1.1'
36
+ recorded_at: Fri, 16 Mar 2012 00:21:37 GMT
37
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,28 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.darkskyapp.com/v1/precipitation/this-is-your-dark-sky-api-key/42.7,-73.6,1325607100;42.0,-73.0,1325607791
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ X-Powered-By:
16
+ - Express
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '167'
21
+ Connection:
22
+ - keep-alive
23
+ body:
24
+ encoding: ASCII-8BIT
25
+ string: ! '{"precipitation":[{"probability":0,"intensity":0,"error":0,"type":"rain","time":1325607100},{"probability":0,"intensity":0,"error":0,"type":"rain","time":1325607791}]}'
26
+ http_version: '1.1'
27
+ recorded_at: Fri, 16 Mar 2012 00:36:48 GMT
28
+ recorded_with: VCR 2.0.0
@@ -1,68 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Darksky::API do
4
- let(:darksky_api) { Darksky::API.new('d41d8cd98f00b204e9800998ecf8427e') }
4
+ let(:darksky_api) { Darksky::API.new('this-is-your-dark-sky-api-key') }
5
5
 
6
6
  describe '#forecast' do
7
- it 'should return a valid forecast for a latitude and longitude' do
8
- darksky_api.stub(:forecast).and_return(JSON.parse(%q(
9
- {
10
- "currentSummary":"Rain",
11
- "hourSummary":"Rain will stop in 25 minutes.",
12
- "station":"enx",
13
-
14
- "precipitation":[
15
- {"probability":1.0,
16
- "intensity":15.6,
17
- "stdev":1.0,
18
- "type":"rain",
19
- "time":1325607311},
20
-
21
- {"probability":0.84,
22
- "intensity":12.0,
23
- "stdev":2.34,
24
- "type":"rain",
25
- "time":1325607431},
26
-
27
- {"probability":0.8,
28
- "intensity":20.5,
29
- "stdev":5.1,
30
- "type":"rain",
31
- "time":1325607551}
32
- ]
33
- }
34
- )))
35
-
36
- forecast = darksky_api.forecast('42.7243','-73.6927')
37
- forecast['currentSummary'].should == 'Rain'
38
- forecast['station'].should == 'enx'
7
+ it 'should return a valid forecast for a latitude and longitude' do
8
+ VCR.use_cassette('forecast', :record => :once) do
9
+ forecast = darksky_api.forecast('42.7243','-73.6927')
10
+ forecast['currentSummary'].should == 'clear'
11
+ forecast['radarStation'].should == 'enx'
12
+ end
39
13
  end
40
14
  end
41
15
 
42
16
  describe '#precipitation' do
43
17
  it 'should return forecasts for a collection of arbitrary points' do
44
- darksky_api.stub(:precipitation).and_return(JSON.parse(%q(
45
- {
46
- "precipitation":[
47
- {"probability":1.0,
48
- "intensity":15.6,
49
- "stdev":1.0,
50
- "type":"rain",
51
- "time":1325607100},
52
-
53
- {"probability":0.0,
54
- "intensity":0.0,
55
- "stdev":0.0,
56
- "type":"rain",
57
- "time":1325607791}
58
- ]
59
- }
60
- )))
18
+ VCR.use_cassette('precipitation', :record => :once) do
19
+ precipitation = darksky_api.precipitation(['42.7','-73.6',1325607100,'42.0','-73.0',1325607791])
20
+ precipitation['precipitation'].size.should == 2
21
+ precipitation['precipitation'].first['probability'].should == 0
22
+ precipitation['precipitation'].first['type'].should == 'rain'
23
+ end
24
+ end
25
+ end
61
26
 
62
- precipitation = darksky_api.precipitation(['42.7','-73.6',1325607100,'42.0','-73.0',1325607791])
63
- precipitation['precipitation'].size.should == 2
64
- precipitation['precipitation'].first['probability'].should == 1.0
65
- precipitation['precipitation'].first['type'].should == 'rain'
27
+ describe '#interesting' do
28
+ it 'should return a list of interesting storms happening right now' do
29
+ VCR.use_cassette('interesting', :record => :once) do
30
+ interesting_storms = darksky_api.interesting
31
+ interesting_storms.size.should == 1
32
+ end
66
33
  end
67
34
  end
68
35
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Darksky::VERSION do
4
4
  it 'should be the correct version' do
5
- Darksky::VERSION.should == '1.0.2'
5
+ Darksky::VERSION.should == '1.0.3'
6
6
  end
7
7
  end
@@ -1,7 +1,14 @@
1
1
  require 'rspec'
2
2
  require 'darksky'
3
+ require 'vcr'
3
4
 
4
5
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
6
 
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/cassettes'
9
+ c.hook_into :typhoeus
10
+ c.allow_http_connections_when_no_cassette = false
11
+ end
12
+
6
13
  RSpec.configure do |config|
7
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darksky
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-12 00:00:00.000000000 Z
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
16
- requirement: &70155687633380 !ruby/object:Gem::Requirement
16
+ requirement: &70289250869220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70155687633380
24
+ version_requirements: *70289250869220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70155687632960 !ruby/object:Gem::Requirement
27
+ requirement: &70289250868760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70155687632960
35
+ version_requirements: *70289250868760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70155687632540 !ruby/object:Gem::Requirement
38
+ requirement: &70289250868320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70155687632540
46
+ version_requirements: *70289250868320
47
+ - !ruby/object:Gem::Dependency
48
+ name: vcr
49
+ requirement: &70289250867900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70289250867900
47
58
  description: Ruby gem for retrieving data from the Dark Sky API
48
59
  email:
49
- - me@davidczarnecki
60
+ - me@davidczarnecki.com
50
61
  executables: []
51
62
  extensions: []
52
63
  extra_rdoc_files: []
@@ -62,6 +73,9 @@ files:
62
73
  - lib/darksky.rb
63
74
  - lib/darksky/api.rb
64
75
  - lib/darksky/version.rb
76
+ - spec/cassettes/forecast.yml
77
+ - spec/cassettes/interesting.yml
78
+ - spec/cassettes/precipitation.yml
65
79
  - spec/darksky/api_spec.rb
66
80
  - spec/darksky/version_spec.rb
67
81
  - spec/spec_helper.rb
@@ -79,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
93
  version: '0'
80
94
  segments:
81
95
  - 0
82
- hash: 1879961532628065117
96
+ hash: -3864416475470659420
83
97
  required_rubygems_version: !ruby/object:Gem::Requirement
84
98
  none: false
85
99
  requirements:
@@ -88,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  version: '0'
89
103
  segments:
90
104
  - 0
91
- hash: 1879961532628065117
105
+ hash: -3864416475470659420
92
106
  requirements: []
93
107
  rubyforge_project: darksky
94
108
  rubygems_version: 1.8.10
@@ -96,6 +110,9 @@ signing_key:
96
110
  specification_version: 3
97
111
  summary: Ruby gem for retrieving data from the Dark Sky API
98
112
  test_files:
113
+ - spec/cassettes/forecast.yml
114
+ - spec/cassettes/interesting.yml
115
+ - spec/cassettes/precipitation.yml
99
116
  - spec/darksky/api_spec.rb
100
117
  - spec/darksky/version_spec.rb
101
118
  - spec/spec_helper.rb