darksky 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .yardoc
6
+ doc
7
+ *.rdb
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.3-p0@darksky_gem
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in darksky.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 David Czarnecki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,36 @@
1
+ # darksky
2
+
3
+ Ruby gem for retrieving data from the [Dark Sky API](http://darkskyapp.com/api/). The Dark Sky API lets you query
4
+ for short-term precipitation forecast data at geographical points inside the United States.
5
+
6
+ ## Installation
7
+
8
+ `gem install darksky`
9
+
10
+ or in your `Gemfile`
11
+
12
+ ```ruby
13
+ gem 'darksky'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ darksky = Darksky::API.new('d41d8cd98f00b204e9800998ecf8427e')
20
+ forecast = darksky.forecast('42.7243','-73.6927')
21
+ precipitation = darksky.precipitation(['42.7','-73.6',1325607100,'42.0','-73.0',1325607791])
22
+ ```
23
+
24
+ ## Contributing to darksky
25
+
26
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
27
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
28
+ * Fork the project
29
+ * Start a feature/bugfix branch
30
+ * Commit and push until you are happy with your contribution
31
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
32
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
33
+
34
+ ## Copyright
35
+
36
+ Copyright (c) 2012 David Czarnecki. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ spec.rspec_opts = ['--backtrace']
8
+ # spec.ruby_opts = ['-w']
9
+ end
10
+
11
+ task :default => :spec
data/darksky.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "darksky/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "darksky"
7
+ s.version = Darksky::VERSION
8
+ s.authors = ["David Czarnecki"]
9
+ s.email = ["me@davidczarnecki"]
10
+ s.homepage = "https://github.com/czarneckid/darksky"
11
+ s.summary = %q{Ruby gem for retrieving data from the Dark Sky API}
12
+ s.description = %q{Ruby gem for retrieving data from the Dark Sky API}
13
+
14
+ s.rubyforge_project = "darksky"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('typhoeus')
22
+
23
+ s.add_development_dependency('rake')
24
+ s.add_development_dependency('rspec')
25
+ end
data/lib/darksky.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'darksky/version'
2
+ require 'darksky/api'
3
+
4
+ module Darksky
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'typhoeus'
2
+ require 'json'
3
+
4
+ module Darksky
5
+ class API
6
+ DARKSKY_API_URL = 'https://api.darkskyapp.com/v1'
7
+
8
+ # Create a new instance of the Darksky::API using your API key.
9
+ #
10
+ # @param api_key [String] Dark Sky API key.
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ end
14
+
15
+ # Returns a forecast for the next hour at a given location.
16
+ #
17
+ # @param latitude [String] Latitude in decimal degrees.
18
+ # @param longitude [String] Longitude in decimal degrees.
19
+ def forecast(latitude, longitude)
20
+ response = Typhoeus::Request.get("#{DARKSKY_API_URL}/forecast/#{@api_key}/#{latitude},#{longitude}")
21
+ JSON.parse(response.body) if response.code == 200
22
+ end
23
+
24
+ # Returns forecasts for a collection of arbitrary points.
25
+ #
26
+ # @param latitudes_longitudes_times [Array] Triplets of latitude, longitude and time. Example: ['42.7','-73.6',1325607100,'42.0','-73.0',1325607791]
27
+ def precipitation(latitudes_longitudes_times)
28
+ return if latitudes_longitudes_times.size % 3 != 0
29
+ response = Typhoeus::Request.get("#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{latitudes_longitudes_times.join(',')}")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Darksky
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Darksky::API do
4
+ let(:darksky_api) { Darksky::API.new('d41d8cd98f00b204e9800998ecf8427e') }
5
+
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'
39
+ end
40
+ end
41
+
42
+ describe '#precipitation' do
43
+ 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
+ )))
61
+
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'
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'darksky'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darksky
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Czarnecki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typhoeus
16
+ requirement: &70209839569900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70209839569900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70209839569480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70209839569480
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70209839569060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70209839569060
47
+ description: Ruby gem for retrieving data from the Dark Sky API
48
+ email:
49
+ - me@davidczarnecki
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rvmrc
56
+ - CHANGELOG.markdown
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.markdown
60
+ - Rakefile
61
+ - darksky.gemspec
62
+ - lib/darksky.rb
63
+ - lib/darksky/api.rb
64
+ - lib/darksky/version.rb
65
+ - spec/darksky/api_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/czarneckid/darksky
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -3643920897857846086
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -3643920897857846086
91
+ requirements: []
92
+ rubyforge_project: darksky
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Ruby gem for retrieving data from the Dark Sky API
97
+ test_files:
98
+ - spec/darksky/api_spec.rb
99
+ - spec/spec_helper.rb