wunderground_ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +137 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/wunderground.rb +68 -0
- data/test/helper.rb +19 -0
- data/test/test_wunderground.rb +167 -0
- metadata +225 -0
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "json", "> 1.4.0"
|
4
|
+
gem "httparty", "> 0.6.0"
|
5
|
+
gem "addressable"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.1"
|
11
|
+
gem "simplecov", ">= 0"
|
12
|
+
gem "mocha", "> 0.9.11"
|
13
|
+
gem "ruby-debug19", :require => "ruby-debug", :platforms => [:ruby_19]
|
14
|
+
gem "ruby-debug", :platforms => [:ruby_18]
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Winfred Nadeau
|
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,137 @@
|
|
1
|
+
# Wunderground Ruby API wrapper
|
2
|
+
|
3
|
+
Wunderground Ruby is an API wrapper for interacting with the [Wunderground API](http://www.wunderground.com/weather/api/)
|
4
|
+
|
5
|
+
|
6
|
+
##Installation
|
7
|
+
|
8
|
+
$ gem install wunderground_ruby
|
9
|
+
|
10
|
+
or in your Gemfile
|
11
|
+
|
12
|
+
gem 'wunderground_ruby'
|
13
|
+
|
14
|
+
##Requirements
|
15
|
+
|
16
|
+
A Wunderground account and API key.
|
17
|
+
If a request is attempted without an APIkey, this wrapper will raise a MissingAPIKey exception
|
18
|
+
|
19
|
+
JSON only at the moment.
|
20
|
+
|
21
|
+
##Usage
|
22
|
+
|
23
|
+
You can create an instance of the API wrapper and pass it the API key:
|
24
|
+
|
25
|
+
w_api = Wunderground.new("your apikey")
|
26
|
+
|
27
|
+
You can also set the environment variable "WUNDERGROUND_API_KEY" and wunderground_ruby will use it when you create an instance:
|
28
|
+
|
29
|
+
w_api = Wunderground.new
|
30
|
+
|
31
|
+
This gem/wrapper uses some method_missing fun to make it easier to get feature and location data from Wunderground
|
32
|
+
|
33
|
+
Any number of [features](http://www.wunderground.com/weather/api/d/documentation.html#request) work by passing the features from the method straight into the request URL.
|
34
|
+
|
35
|
+
Check out below and test file for more examples.
|
36
|
+
|
37
|
+
Standard request breakdown:
|
38
|
+
|
39
|
+
wrapper_object.get_[feature]_and_[another feature]_for(optional_hash,"and/or location string")
|
40
|
+
|
41
|
+
##Optional Hash
|
42
|
+
|
43
|
+
This ugly little guy handles the nonconformists in Wunderground's API request structure. Luckily there are only two of these baddies. (details below)
|
44
|
+
|
45
|
+
optional_hash = {lang: "FR", geo_ip:"127.0.0.1"}
|
46
|
+
|
47
|
+
Can you think of a better way to handle these? Pull requests welcome.
|
48
|
+
|
49
|
+
##Features
|
50
|
+
|
51
|
+
The method_missing magic happens here.
|
52
|
+
|
53
|
+
w_api.get_forecast_for("WA","Spokane")
|
54
|
+
w_api.get_forecast_and_conditions_for("1234.1234,-1234.1234") #a lat/long string
|
55
|
+
w_api.get_webcams_and_conditions_and_alerts_for("33043") #a zipcode
|
56
|
+
|
57
|
+
##Locations
|
58
|
+
|
59
|
+
Any location string that Wunderground accepts will pass straight through this wrapper to their API, _except for a specific geo-ip._ (examples below)
|
60
|
+
|
61
|
+
#there is some handy array joining, if needed
|
62
|
+
w_api.get_forecast_for("WA/Spokane") #equivalent to the next example
|
63
|
+
w_api.get_forecast_for("WA","Spokane") #equivalent to the previous example
|
64
|
+
|
65
|
+
#zipcodes,lat/long, aiport codes, all of them just pass straight through this wrapper and into the request URL
|
66
|
+
w_api.get_conditions_for("77898")
|
67
|
+
|
68
|
+
#weather station code uniqueness - they use the 'pws:' prefix for weather station codes. So does this wrapper.
|
69
|
+
w_api.get_conditions_for("pws:STATIONCODE")
|
70
|
+
|
71
|
+
w_api.get_conditions_for("autoip") #passes straight through, but only gets the weather for your server's IP, so not very useful probably
|
72
|
+
|
73
|
+
For geocoding a specific ip address, just provide in a an IP like this:
|
74
|
+
|
75
|
+
w_api.get_alerts_for({geo_ip: "127.0.0.1"})
|
76
|
+
|
77
|
+
This was the quickest workaround to the non-conformity of the auto_ip request format.
|
78
|
+
|
79
|
+
|
80
|
+
##Language Support
|
81
|
+
|
82
|
+
Because the Language modifier in Wunderground's request structure uses a colon, which doesn't jive with the method_missing design, adding a specific language to one request can be done like this:
|
83
|
+
|
84
|
+
w_api.get_forecast_for({lang:"FR"},"France","Paris")
|
85
|
+
|
86
|
+
Also, you can set the default language in the constructor or with a setter.
|
87
|
+
|
88
|
+
w_api = Wunderground.new("apikey",{language: "FR"})
|
89
|
+
w_api.language = 'FR'
|
90
|
+
w_api.get_forecast_for("France","Paris") #automatically includes /lang:FR/ in the request url, so results will be in French
|
91
|
+
w_api.get_forecast_for({lang:"DE"},"France","Paris") #this will override the French(FR) default with German(DE)
|
92
|
+
|
93
|
+
##History Support
|
94
|
+
|
95
|
+
While it is possible to call
|
96
|
+
|
97
|
+
w_api.get_history20101231_for("77789")
|
98
|
+
|
99
|
+
to get the history data for this date/location. You may enjoy more flexibility when using get_history_for:
|
100
|
+
|
101
|
+
w_api.get_history_for("20101010","AL","Birmingham")
|
102
|
+
w_api.get_history_for(1.year.ago,"33909")
|
103
|
+
w_api.get_history_for(Date.now, {lang: "FR"}, "France/Paris")
|
104
|
+
w_api.get_history_for(Date.now, {lang: "DE", geo_ip:"123.4.5.6"})
|
105
|
+
|
106
|
+
.get_history_for accepts a string or any Date/Time/DateTime object that responds to .strftime("%Y%m%d") to auto-format the date.
|
107
|
+
|
108
|
+
|
109
|
+
### Other Stuff
|
110
|
+
|
111
|
+
wunderground_ruby defaults to a 30 second timeout. You can optionally set your own timeout (in seconds) like so:
|
112
|
+
|
113
|
+
w_api = Wunderground.new("apikey",{timeout: 60})
|
114
|
+
w_api.timeout = 5
|
115
|
+
|
116
|
+
|
117
|
+
### Error Handling
|
118
|
+
|
119
|
+
By default you are expected to handle errors returned by the APIs manually. (see their documentation for more information about these errors)
|
120
|
+
|
121
|
+
If you set the `throws_exceptions` boolean attribute for a given instance then
|
122
|
+
wunderground_ruby will attempt to intercept the errors and raise an APIError exception if you feel like catching it.
|
123
|
+
|
124
|
+
##Contributing
|
125
|
+
|
126
|
+
Do eet.
|
127
|
+
|
128
|
+
##Thanks
|
129
|
+
|
130
|
+
* [Amro Mousa](https://github.com/amro) - design inspiration (*cough* stolen)
|
131
|
+
|
132
|
+
|
133
|
+
##Copyrights
|
134
|
+
|
135
|
+
* Copyright (c) 2012 Winfred Nadeau. See LICENSE.txt for details.
|
136
|
+
|
137
|
+
Winfred Nadeau is not affiliated with [Wunderground.com](http://wunderground.com), so check them out for licensing/copyright/legal/TOS details regarding their API and their data.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "wunderground_ruby"
|
16
|
+
gem.homepage = "http://github.com/wnadeau/wunderground_ruby"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A simple ruby API wrapper for interacting with the Wunderground API}
|
19
|
+
gem.description = %Q{A simple ruby API wrapper for interacting with the Wunderground API}
|
20
|
+
gem.email = "winfred.nadeau@gmail.com"
|
21
|
+
gem.authors = ["Winfred Nadeau"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'httparty', '> 0.6.0'
|
25
|
+
gem.add_runtime_dependency 'json', '> 1.4.0'
|
26
|
+
gem.add_development_dependency 'shoulda', '> 0.0.0'
|
27
|
+
gem.add_development_dependency 'mocha', '> 0.9.11'
|
28
|
+
gem.add_development_dependency 'simplecov', '> 0'
|
29
|
+
#gem.add_development_dependency 'rspec', '> 1.2.3'
|
30
|
+
end
|
31
|
+
Jeweler::RubygemsDotOrgTasks.new
|
32
|
+
|
33
|
+
require 'rake/testtask'
|
34
|
+
Rake::TestTask.new(:test) do |test|
|
35
|
+
test.libs << 'lib' << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "Wunderground #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
51
|
+
desc "Open an irb session preloaded with this library"
|
52
|
+
task :console do
|
53
|
+
sh "irb -rubygems -I lib -r wunderground_pound"
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/wunderground.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
require 'addressable/uri'
|
5
|
+
|
6
|
+
class Wunderground
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
default_timeout 30
|
10
|
+
|
11
|
+
class MissingAPIKey < RuntimeError; end
|
12
|
+
class APIError < RuntimeError; end
|
13
|
+
|
14
|
+
attr_accessor :api_key, :timeout, :throws_exceptions, :language
|
15
|
+
|
16
|
+
def initialize(api_key = nil, extra_params = {})
|
17
|
+
@api_key = api_key || ENV['WUNDERGROUND_API_KEY'] || ENV['WUNDERGROUND_APIKEY'] || self.class.api_key
|
18
|
+
@timeout = extra_params[:timeout] || 30
|
19
|
+
@throws_exceptions = extra_params[:throws_exceptions] || false
|
20
|
+
@language = extra_params[:language]
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_api_url
|
24
|
+
"http://api.wunderground.com/api/#{api_key}/"
|
25
|
+
end
|
26
|
+
def get_history_for(date,*args)
|
27
|
+
history = (date.class == String ? "history_#{date}" : "history_#{date.strftime("%Y%m%d")}")
|
28
|
+
send("get_#{history}_for",args)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def call(method, params = {})
|
34
|
+
raise MissingAPIKey if @api_key.nil?
|
35
|
+
response = self.class.get(base_api_url << method, :timeout => @timeout)
|
36
|
+
begin
|
37
|
+
response = JSON.parse(response.body)
|
38
|
+
rescue
|
39
|
+
response = response.body
|
40
|
+
end
|
41
|
+
|
42
|
+
if @throws_exceptions && response.is_a?(Hash) && response["response"]["error"]
|
43
|
+
raise APIError, "#{response["response"]["error"]["type"]}: #{response["response"]["error"]["description"]})"
|
44
|
+
end
|
45
|
+
|
46
|
+
response
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(method, *args)
|
50
|
+
raise NoMethodError, "undefined method: #{method} for Wunderground" unless method.to_s.start_with?("get_") and method.to_s.end_with?("_for")
|
51
|
+
url = method.to_s.gsub("get_","").gsub("_for","").gsub("_and_","/")
|
52
|
+
url << "/lang:#{@language}" if @language
|
53
|
+
if Hash.try_convert(args[0])
|
54
|
+
url = url.sub(/\/lang:.*/,'') and url << "/lang:#{args[0][:lang]}" if args[0][:lang]
|
55
|
+
ip_address = args[0][:geo_ip] and args.push("autoip") if args[0][:geo_ip]
|
56
|
+
args.delete_at(0)
|
57
|
+
end
|
58
|
+
call(url <<'/q/'<< args.join('/') << ".json" << (ip_address.nil? ? '': "?geo_ip=#{ip_address}"))
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
attr_accessor :api_key, :timeout
|
63
|
+
def method_missing(sym, *args, &block)
|
64
|
+
new(self.api_key, self.attributes).send(sym, *args, &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'test/unit'
|
13
|
+
require 'shoulda'
|
14
|
+
require 'mocha'
|
15
|
+
|
16
|
+
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
require 'wunderground'
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'cgi'
|
3
|
+
require 'ruby-debug'
|
4
|
+
require 'addressable/uri'
|
5
|
+
|
6
|
+
class TestWunderground < Test::Unit::TestCase
|
7
|
+
|
8
|
+
context "attributes" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@api_key = "12345"
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have no API by default" do
|
15
|
+
@wunderground = Wunderground.new
|
16
|
+
assert_equal(nil, @wunderground.api_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set an API key in constructor" do
|
20
|
+
@wunderground = Wunderground.new(@api_key)
|
21
|
+
assert_equal(@api_key, @wunderground.api_key)
|
22
|
+
end
|
23
|
+
should 'set timeout in constructor' do
|
24
|
+
@wunderground = Wunderground.new(@api_key,{timeout: 60})
|
25
|
+
assert_equal(60,@wunderground.timeout)
|
26
|
+
end
|
27
|
+
should 'set language in constructor' do
|
28
|
+
@wunderground = Wunderground.new(@apikey,{language:"FR"})
|
29
|
+
assert_equal('FR',@wunderground.language)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "set an API key from the 'WUNDERGROUND_API_KEY' ENV variable" do
|
33
|
+
ENV['WUNDERGROUND_API_KEY'] = @api_key
|
34
|
+
@wunderground = Wunderground.new
|
35
|
+
assert_equal(@api_key, @wunderground.api_key)
|
36
|
+
ENV.delete('WUNDERGROUND_API_KEY')
|
37
|
+
end
|
38
|
+
|
39
|
+
should "set an API key from the 'WUNDERGROUND_APIKEY' ENV variable" do
|
40
|
+
ENV['WUNDERGROUND_APIKEY'] = @api_key
|
41
|
+
@wunderground = Wunderground.new
|
42
|
+
assert_equal(@api_key, @wunderground.api_key)
|
43
|
+
ENV.delete('WUNDERGROUND_APIKEY')
|
44
|
+
end
|
45
|
+
|
46
|
+
should "set an API key via setter" do
|
47
|
+
@wunderground = Wunderground.new
|
48
|
+
@wunderground.api_key = @api_key
|
49
|
+
assert_equal(@api_key, @wunderground.api_key)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "set and get timeout" do
|
53
|
+
@wunderground = Wunderground.new
|
54
|
+
timeout = 30
|
55
|
+
@wunderground.timeout = timeout
|
56
|
+
assert_equal(timeout, @wunderground.timeout)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "api url" do
|
61
|
+
setup do
|
62
|
+
@wunderground = Wunderground.new
|
63
|
+
@wunderground.api_key = '123'
|
64
|
+
@url = "http://api.wunderground.com/api/"
|
65
|
+
end
|
66
|
+
should "raise exception at empty api key" do
|
67
|
+
@wunderground.api_key=nil
|
68
|
+
expect_get(@url,{timeout:30})
|
69
|
+
assert_raise Wunderground::MissingAPIKey do
|
70
|
+
@wunderground.get_forecast_for("CA","San Fransisco")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
should "contain api key" do
|
75
|
+
expect_get(@url+"123/forecast/q/ME/Portland.json",{timeout:30})
|
76
|
+
@wunderground.get_forecast_for("ME","Portland")
|
77
|
+
end
|
78
|
+
should 'contain multiple Wunderground methods from ruby method' do
|
79
|
+
expect_get(@url+"123/forecast/conditions/q/.json",{timeout: 30})
|
80
|
+
@wunderground.get_forecast_and_conditions_for()
|
81
|
+
end
|
82
|
+
should 'contain language modifier for method with {lang:"code"} hash' do
|
83
|
+
expect_get(@url+"123/forecast/lang:FR/q/ME/Portland.json",{timeout: 30})
|
84
|
+
@wunderground.get_forecast_for({lang:'FR'},"ME","Portland")
|
85
|
+
end
|
86
|
+
context 'location parameter' do
|
87
|
+
should 'formats query of type array' do
|
88
|
+
expect_get(@url+"123/forecast/q/ME/Portland.json",{timeout: 30})
|
89
|
+
@wunderground.get_forecast_for("ME","Portland")
|
90
|
+
end
|
91
|
+
should 'formats query of type string' do
|
92
|
+
expect_get(@url+"123/forecast/q/1234.1234,-1234.1234.json",{timeout: 30})
|
93
|
+
@wunderground.get_forecast_for("1234.1234,-1234.1234")
|
94
|
+
expect_get(@url+"123/forecast/q/pws:WHAT.json",{timeout: 30})
|
95
|
+
@wunderground.get_forecast_for("pws:WHAT")
|
96
|
+
end
|
97
|
+
should 'formats query of type geo_ip' do
|
98
|
+
expect_get(@url+"123/forecast/q/autoip.json?geo_ip=127.0.0.1",{timeout: 30})
|
99
|
+
@wunderground.get_forecast_for({geo_ip: "127.0.0.1"})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
context 'default language' do
|
103
|
+
setup {@wunderground.language = "FR"}
|
104
|
+
should 'automatically set language for all location types' do
|
105
|
+
expect_get(@url+"123/forecast/lang:FR/q/pws:KCATAHOE2.json",{timeout: 30})
|
106
|
+
@wunderground.get_forecast_for("pws:KCATAHOE2")
|
107
|
+
end
|
108
|
+
should 'have optional language override on call' do
|
109
|
+
expect_get(@url+"123/forecast/lang:DE/q/ME/Portland.json",{timeout: 30})
|
110
|
+
@wunderground.get_forecast_for({lang: "DE"},"ME","Portland")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
context 'for optional get_history_for(date,location)' do
|
114
|
+
should 'pass string dates straight to URL' do
|
115
|
+
expect_get(@url+"123/history_20110121/q/ME/Portland.json",{timeout: 30})
|
116
|
+
@wunderground.get_history_for("20110121","ME","Portland")
|
117
|
+
end
|
118
|
+
should 'accept Time objects' do
|
119
|
+
expect_get(@url+"123/history_#{Time.now.strftime("%Y%m%d")}/q/ME/Portland.json",{timeout: 30})
|
120
|
+
@wunderground.get_history_for(Time.now,"ME","Portland")
|
121
|
+
end
|
122
|
+
should 'accept Date objects' do
|
123
|
+
expect_get(@url+"123/history_#{Time.now.strftime("%Y%m%d")}/q/ME/Portland.json",{timeout: 30})
|
124
|
+
@wunderground.get_history_for(Time.now.to_date,"ME","Portland")
|
125
|
+
end
|
126
|
+
should 'accept DateTime objects' do
|
127
|
+
expect_get(@url+"123/history_#{Time.now.strftime("%Y%m%d")}/q/ME/Portland.json",{timeout: 30})
|
128
|
+
@wunderground.get_history_for(Time.now.to_datetime,"ME","Portland")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
context "Wunderground instances" do
|
135
|
+
setup do
|
136
|
+
@key = "TESTKEY"
|
137
|
+
@wunderground = Wunderground.new(@key)
|
138
|
+
@url = "http://api.wunderground.com/api/TESTKEY/forecast/q/ME/Portland.json"
|
139
|
+
@returns = Struct.new(:body).new(["array", "entries"].to_json)
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
should 'throw exception if non-standard get_function_for(location) method is called' do
|
144
|
+
assert_raise NoMethodError do
|
145
|
+
@wunderground.scramble
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
should "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
150
|
+
@wunderground.throws_exceptions = true
|
151
|
+
Wunderground.stubs(:get).returns(Struct.new(:body).new({response:{'error' => 'bad things'}}.to_json))
|
152
|
+
assert_raise Wunderground::APIError do
|
153
|
+
@wunderground.get_forecast_for("CA","San_Fransisco")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def expect_get(expected_url,expected_options)
|
162
|
+
Wunderground.expects(:get).with{|url, opts|
|
163
|
+
url == expected_url &&
|
164
|
+
opts[:timeout] == expected_options[:timeout]
|
165
|
+
}.returns(Struct.new(:body).new("") )
|
166
|
+
end
|
167
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wunderground_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Winfred Nadeau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70152356297300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70152356297300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &70152356296360 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>'
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.6.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70152356296360
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: addressable
|
38
|
+
requirement: &70152356295400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70152356295400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: shoulda
|
49
|
+
requirement: &70152356294520 !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: *70152356294520
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &70152356272440 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70152356272440
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: &70152356271540 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.5.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70152356271540
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: simplecov
|
82
|
+
requirement: &70152356270760 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70152356270760
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: mocha
|
93
|
+
requirement: &70152356269880 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>'
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.9.11
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70152356269880
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: ruby-debug19
|
104
|
+
requirement: &70152356268860 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70152356268860
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: ruby-debug
|
115
|
+
requirement: &70152356267820 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70152356267820
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: httparty
|
126
|
+
requirement: &70152356267000 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>'
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.6.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *70152356267000
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: json
|
137
|
+
requirement: &70152356265660 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>'
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 1.4.0
|
143
|
+
type: :runtime
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: *70152356265660
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: shoulda
|
148
|
+
requirement: &70152356249020 !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>'
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.0.0
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: *70152356249020
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
name: mocha
|
159
|
+
requirement: &70152356247860 !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>'
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: 0.9.11
|
165
|
+
type: :development
|
166
|
+
prerelease: false
|
167
|
+
version_requirements: *70152356247860
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: simplecov
|
170
|
+
requirement: &70152356246360 !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ! '>'
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: *70152356246360
|
179
|
+
description: A simple ruby API wrapper for interacting with the Wunderground API
|
180
|
+
email: winfred.nadeau@gmail.com
|
181
|
+
executables: []
|
182
|
+
extensions: []
|
183
|
+
extra_rdoc_files:
|
184
|
+
- LICENSE.txt
|
185
|
+
- README.markdown
|
186
|
+
files:
|
187
|
+
- Gemfile
|
188
|
+
- LICENSE.txt
|
189
|
+
- README.markdown
|
190
|
+
- Rakefile
|
191
|
+
- VERSION
|
192
|
+
- lib/wunderground.rb
|
193
|
+
- test/helper.rb
|
194
|
+
- test/test_wunderground.rb
|
195
|
+
homepage: http://github.com/wnadeau/wunderground_ruby
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ! '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
segments:
|
209
|
+
- 0
|
210
|
+
hash: 431265459336154521
|
211
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
|
+
none: false
|
213
|
+
requirements:
|
214
|
+
- - ! '>='
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
requirements: []
|
218
|
+
rubyforge_project:
|
219
|
+
rubygems_version: 1.8.10
|
220
|
+
signing_key:
|
221
|
+
specification_version: 3
|
222
|
+
summary: A simple ruby API wrapper for interacting with the Wunderground API
|
223
|
+
test_files:
|
224
|
+
- test/helper.rb
|
225
|
+
- test/test_wunderground.rb
|