wunderground 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,10 +6,9 @@ gem "addressable"
6
6
 
7
7
  group :development, :test do
8
8
  gem "shoulda", ">= 0"
9
- gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.5.1"
9
+ gem "bundler"
10
+ gem "jeweler"
11
11
  gem "simplecov", ">= 0"
12
12
  gem "mocha", "> 0.9.11"
13
- gem "ruby-debug19", :require => "ruby-debug", :platforms => [:ruby_19]
14
- gem "ruby-debug", :platforms => [:ruby_18]
13
+ gem 'pry'
15
14
  end
data/README.markdown CHANGED
@@ -5,11 +5,11 @@ Wunderground Ruby is an API wrapper for interacting with the [Wunderground API](
5
5
 
6
6
  ##Installation
7
7
 
8
- $ gem install wunderground_ruby
8
+ $ gem install wunderground
9
9
 
10
10
  or in your Gemfile
11
11
 
12
- gem 'wunderground_ruby'
12
+ gem 'wunderground'
13
13
 
14
14
  ##Requirements
15
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/wunderground.rb CHANGED
@@ -23,10 +23,12 @@ class Wunderground
23
23
  def base_api_url
24
24
  "http://api.wunderground.com/api/#{api_key}/"
25
25
  end
26
+
26
27
  def history_for(date,*args)
27
28
  history = (date.class == String ? "history_#{date}" : "history_#{date.strftime("%Y%m%d")}")
28
29
  send("#{history}_for",*args)
29
30
  end
31
+
30
32
  def planner_for(date,*args)
31
33
  send("planner_#{date}_for",args) and return if date.class == String
32
34
  range = date.strftime("%m%d") << args[0].strftime("%m%d")
@@ -34,7 +36,11 @@ class Wunderground
34
36
  send("planner_#{range}_for",*args)
35
37
  end
36
38
 
37
- protected
39
+ def respond_to?(method)
40
+ method_missing_match?(method) || super(method)
41
+ end
42
+
43
+ protected
38
44
 
39
45
  def call(method, timeout)
40
46
  raise MissingAPIKey if @api_key.nil?
@@ -53,7 +59,7 @@ protected
53
59
  end
54
60
 
55
61
  def method_missing(method, *args)
56
- raise NoMethodError, "undefined method: #{method} for Wunderground" unless method.to_s.end_with?("_for")
62
+ super(method, *args) unless method_missing_match?(method)
57
63
  url = method.to_s.gsub("_for","").gsub("_and_","/")
58
64
  url << "/lang:#{@language}" if @language
59
65
  if args.last.instance_of? Hash
@@ -71,5 +77,10 @@ protected
71
77
  new(self.api_key, self.attributes).send(sym, *args, &block)
72
78
  end
73
79
  end
74
- end
75
80
 
81
+ private
82
+
83
+ def method_missing_match?(method)
84
+ method.to_s.end_with?("_for")
85
+ end
86
+ end
data/test/helper.rb CHANGED
@@ -11,7 +11,8 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'test/unit'
13
13
  require 'shoulda'
14
- require 'mocha'
14
+ require 'mocha/setup'
15
+ require 'pry'
15
16
 
16
17
 
17
18
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,6 +1,5 @@
1
1
  require 'helper'
2
2
  require 'cgi'
3
- require 'ruby-debug'
4
3
  require 'addressable/uri'
5
4
 
6
5
  class TestWunderground < Test::Unit::TestCase
@@ -58,9 +57,9 @@ class TestWunderground < Test::Unit::TestCase
58
57
  @wunderground = Wunderground.new("123")
59
58
  @url = "http://api.wunderground.com/api/123/"
60
59
  end
60
+
61
61
  should "raise exception at empty api key" do
62
62
  @wunderground.api_key=nil
63
- expect_get(@url,{timeout:30})
64
63
  assert_raise Wunderground::MissingAPIKey do
65
64
  @wunderground.forecast_for("CA","San Fransisco")
66
65
  end
@@ -70,93 +69,113 @@ class TestWunderground < Test::Unit::TestCase
70
69
  expect_get(@url+"forecast/q/ME/Portland.json",{timeout:30})
71
70
  @wunderground.forecast_for("ME","Portland")
72
71
  end
72
+
73
73
  should 'contain multiple Wunderground methods from ruby method' do
74
74
  expect_get(@url+"forecast/conditions/q/.json",{timeout: 30})
75
75
  @wunderground.forecast_and_conditions_for()
76
76
  end
77
+
77
78
  should 'contain language modifier for method with {lang:"code"} hash' do
78
79
  expect_get(@url+"forecast/lang:FR/q/ME/Portland.json",{timeout: 30})
79
80
  @wunderground.forecast_for("ME","Portland", lang: 'FR')
80
81
  end
82
+
81
83
  context 'location parameter' do
82
84
  should 'formats query of type array' do
83
85
  expect_get(@url+"forecast/q/ME/Portland.json",{timeout: 30})
84
86
  @wunderground.forecast_for("ME","Portland")
85
87
  end
88
+
86
89
  should 'formats query of type string' do
87
90
  expect_get(@url+"forecast/q/1234.1234,-1234.1234.json",{timeout: 30})
88
91
  @wunderground.forecast_for("1234.1234,-1234.1234")
89
92
  expect_get(@url+"forecast/q/pws:WHAT.json",{timeout: 30})
90
93
  @wunderground.forecast_for("pws:WHAT")
91
94
  end
95
+
92
96
  should 'formats query of type geo_ip' do
93
97
  expect_get(@url+"forecast/q/autoip.json?geo_ip=127.0.0.1",{timeout: 30})
94
98
  @wunderground.forecast_for(geo_ip: "127.0.0.1")
95
99
  end
96
100
  end
101
+
97
102
  context 'language support' do
98
103
  setup {@wunderground.language = "FR"}
104
+
99
105
  should 'automatically set language for all location types' do
100
106
  expect_get(@url+"forecast/lang:FR/q/pws:KCATAHOE2.json",{timeout: 30})
101
107
  @wunderground.forecast_for("pws:KCATAHOE2")
102
108
  end
109
+
103
110
  should 'have optional language override on call' do
104
111
  expect_get(@url+"forecast/lang:DE/q/ME/Portland.json",{timeout: 30})
105
112
  @wunderground.forecast_for("ME","Portland", lang: 'DE')
106
113
  end
114
+
107
115
  should 'pass language through history helper' do
108
116
  expect_get(@url+"history_#{Time.now.strftime("%Y%m%d")}/lang:DE/q/ME/Portland.json",{timeout: 30})
109
117
  @wunderground.history_for(Time.now,"ME","Portland",lang: 'DE')
110
118
  end
119
+
111
120
  should 'pass language through planner helper' do
112
121
  expect_get(@url+"planner_#{Time.now.strftime("%m%d")}#{(Time.now + 700000).strftime('%m%d')}/lang:DE/q/ME/Portland.json",{timeout: 30})
113
122
  @wunderground.planner_for(Time.now,(Time.now+700000),"ME","Portland", lang: 'DE')
114
123
  end
124
+
115
125
  should 'pass language through planner helper with IP' do
116
126
  expect_get(@url+"planner_#{Time.now.strftime('%m%d')}#{(Time.now +
117
127
  700000).strftime('%m%d')}/lang:DE/q/autoip.json?geo_ip=127.0.0.1",{timeout: 30})
118
128
  @wunderground.planner_for(Time.now,(Time.now+700000),lang: "DE",geo_ip: "127.0.0.1")
119
129
  end
130
+
120
131
  should 'encode string arguments' do
121
132
  expect_get(@url+"planner_#{Time.now.strftime('%m%d')}#{(Time.now +
122
133
  700000).strftime('%m%d')}/lang:DE/q/autoip.json?geo_ip=127.0.0.1",{timeout: 30})
123
134
  @wunderground.planner_for(Time.now,(Time.now+700000),lang: "DE",geo_ip: "127.0.0.1")
124
135
  end
125
136
  end
137
+
126
138
  context 'for history_for(date,location) helper' do
127
139
  should 'pass string dates straight to URL' do
128
140
  expect_get(@url+"history_20110121/q/ME/Portland.json",{timeout: 30})
129
141
  @wunderground.history_for("20110121","ME","Portland")
130
142
  end
143
+
131
144
  should 'accept Time objects' do
132
145
  expect_get(@url+"history_#{Time.now.strftime("%Y%m%d")}/q/ME/Portland.json",{timeout: 30})
133
146
  @wunderground.history_for(Time.now,"ME","Portland")
134
147
  end
148
+
135
149
  should 'accept Date objects' do
136
150
  expect_get(@url+"history_#{Time.now.strftime("%Y%m%d")}/q/ME/Portland.json",{timeout: 30})
137
151
  @wunderground.history_for(Time.now.to_date,"ME","Portland")
138
152
  end
153
+
139
154
  should 'accept Date object and pass optional hash object' do
140
155
  expect_get(@url+"history_#{Time.now.strftime("%Y%m%d")}/lang:FR/q/autoip.json?geo_ip=127.0.0.1",{timeout: 30})
141
156
  @wunderground.history_for(Time.now.to_datetime,geo_ip: '127.0.0.1',lang: 'FR')
142
157
  end
143
158
  end
159
+
144
160
  context 'for planner_for helper' do
145
161
  should 'pass string date ranges through' do
146
162
  expect_get(@url+"planner_03130323/q/ME/Portland.json",timeout: 30)
147
163
  @wunderground.planner_for("03130323","ME","Portland")
148
164
  end
165
+
149
166
  should 'turn two date objects into a properly formatted string' do
150
167
  expect_get(@url+"planner_#{Time.now.strftime('%m%d')}#{(Time.now +
151
168
  700000).strftime('%m%d')}/lang:FR/q/autoip.json?geo_ip=127.0.0.1",timeout: 30)
152
169
  @wunderground.planner_for(Time.now,(Time.now + 700000),geo_ip: '127.0.0.1',lang:'FR')
153
170
  end
154
171
  end
172
+
155
173
  context 'timeout passed through optional hash' do
156
174
  should 'work for helper' do
157
175
  expect_get(@url+"planner_#{Time.now.strftime('%m%d')}#{(Time.now+700000).strftime('%m%d')}/lang:FR/q/autoip.json?geo_ip=127.0.0.1",timeout: 60)
158
176
  @wunderground.planner_for(Time.now,(Time.now + 700000),geo_ip: '127.0.0.1',lang:'FR',timeout: 60)
159
177
  end
178
+
160
179
  should 'work for regular calls' do
161
180
  expect_get(@url+"forecast/q/pws:WHAT.json",timeout: 60)
162
181
  @wunderground.forecast_for("pws:WHAT", timeout: 60)
@@ -173,7 +192,6 @@ class TestWunderground < Test::Unit::TestCase
173
192
  @returns = Struct.new(:body).new(["array", "entries"].to_json)
174
193
  end
175
194
 
176
-
177
195
  should 'throw exception if non-standard function_for(location) method is called' do
178
196
  assert_raise NoMethodError do
179
197
  @wunderground.scramble
@@ -189,6 +207,12 @@ class TestWunderground < Test::Unit::TestCase
189
207
  end
190
208
  end
191
209
 
210
+ context 'respond_to?' do
211
+ should 'respond to anything ending in _for' do
212
+ assert_equal true, Wunderground.new.respond_to?(:any_feature_for)
213
+ end
214
+ end
215
+
192
216
 
193
217
  private
194
218
 
data/wunderground.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wunderground"
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Winfred Nadeau"]
12
- s.date = "2012-07-03"
12
+ s.date = "2013-05-03"
13
13
  s.description = "A simple ruby API wrapper for interacting with the Wunderground API"
14
14
  s.email = "winfred.nadeau@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -31,12 +31,8 @@ Gem::Specification.new do |s|
31
31
  s.homepage = "http://github.com/wnadeau/wunderground_ruby"
32
32
  s.licenses = ["MIT"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = "1.8.10"
34
+ s.rubygems_version = "1.8.25"
35
35
  s.summary = "A simple ruby API wrapper for interacting with the Wunderground API"
36
- s.test_files = [
37
- "test/helper.rb",
38
- "test/test_wunderground.rb"
39
- ]
40
36
 
41
37
  if s.respond_to? :specification_version then
42
38
  s.specification_version = 3
@@ -46,35 +42,32 @@ Gem::Specification.new do |s|
46
42
  s.add_runtime_dependency(%q<httparty>, ["> 0.6.0"])
47
43
  s.add_runtime_dependency(%q<addressable>, [">= 0"])
48
44
  s.add_development_dependency(%q<shoulda>, [">= 0"])
49
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
45
+ s.add_development_dependency(%q<bundler>, [">= 0"])
46
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
51
47
  s.add_development_dependency(%q<simplecov>, [">= 0"])
52
48
  s.add_development_dependency(%q<mocha>, ["> 0.9.11"])
53
- s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
54
- s.add_development_dependency(%q<ruby-debug>, [">= 0"])
49
+ s.add_development_dependency(%q<pry>, [">= 0"])
55
50
  else
56
51
  s.add_dependency(%q<json>, ["> 1.4.0"])
57
52
  s.add_dependency(%q<httparty>, ["> 0.6.0"])
58
53
  s.add_dependency(%q<addressable>, [">= 0"])
59
54
  s.add_dependency(%q<shoulda>, [">= 0"])
60
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
57
  s.add_dependency(%q<simplecov>, [">= 0"])
63
58
  s.add_dependency(%q<mocha>, ["> 0.9.11"])
64
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
65
- s.add_dependency(%q<ruby-debug>, [">= 0"])
59
+ s.add_dependency(%q<pry>, [">= 0"])
66
60
  end
67
61
  else
68
62
  s.add_dependency(%q<json>, ["> 1.4.0"])
69
63
  s.add_dependency(%q<httparty>, ["> 0.6.0"])
70
64
  s.add_dependency(%q<addressable>, [">= 0"])
71
65
  s.add_dependency(%q<shoulda>, [">= 0"])
72
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
66
+ s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
68
  s.add_dependency(%q<simplecov>, [">= 0"])
75
69
  s.add_dependency(%q<mocha>, ["> 0.9.11"])
76
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
77
- s.add_dependency(%q<ruby-debug>, [">= 0"])
70
+ s.add_dependency(%q<pry>, [">= 0"])
78
71
  end
79
72
  end
80
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wunderground
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-07-03 00:00:00.000000000Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70184098296440 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>'
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70184098296440
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: httparty
27
- requirement: &70184098295860 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>'
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.6.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70184098295860
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: addressable
38
- requirement: &70184098295260 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70184098295260
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: shoulda
49
- requirement: &70184098294680 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,32 +69,47 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70184098294680
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: bundler
60
- requirement: &70184098294100 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
- - - ~>
83
+ - - ! '>='
64
84
  - !ruby/object:Gem::Version
65
- version: 1.0.0
85
+ version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70184098294100
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: jeweler
71
- requirement: &70184098293560 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
- - - ~>
99
+ - - ! '>='
75
100
  - !ruby/object:Gem::Version
76
- version: 1.5.1
101
+ version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70184098293560
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: simplecov
82
- requirement: &70184098292980 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70184098292980
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: mocha
93
- requirement: &70184098292400 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>'
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: 0.9.11
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70184098292400
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>'
140
+ - !ruby/object:Gem::Version
141
+ version: 0.9.11
102
142
  - !ruby/object:Gem::Dependency
103
- name: ruby-debug19
104
- requirement: &70184098291460 !ruby/object:Gem::Requirement
143
+ name: pry
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,18 +149,12 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70184098291460
113
- - !ruby/object:Gem::Dependency
114
- name: ruby-debug
115
- requirement: &70184098288900 !ruby/object:Gem::Requirement
152
+ version_requirements: !ruby/object:Gem::Requirement
116
153
  none: false
117
154
  requirements:
118
155
  - - ! '>='
119
156
  - !ruby/object:Gem::Version
120
157
  version: '0'
121
- type: :development
122
- prerelease: false
123
- version_requirements: *70184098288900
124
158
  description: A simple ruby API wrapper for interacting with the Wunderground API
125
159
  email: winfred.nadeau@gmail.com
126
160
  executables: []
@@ -154,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
188
  version: '0'
155
189
  segments:
156
190
  - 0
157
- hash: -3588021643652236154
191
+ hash: -4516707908487803297
158
192
  required_rubygems_version: !ruby/object:Gem::Requirement
159
193
  none: false
160
194
  requirements:
@@ -163,10 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
197
  version: '0'
164
198
  requirements: []
165
199
  rubyforge_project:
166
- rubygems_version: 1.8.10
200
+ rubygems_version: 1.8.25
167
201
  signing_key:
168
202
  specification_version: 3
169
203
  summary: A simple ruby API wrapper for interacting with the Wunderground API
170
- test_files:
171
- - test/helper.rb
172
- - test/test_wunderground.rb
204
+ test_files: []