attack-barometer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +266 -0
- data/VERSION.yml +4 -0
- data/bin/barometer +63 -0
- data/lib/barometer/base.rb +52 -0
- data/lib/barometer/data/current.rb +93 -0
- data/lib/barometer/data/distance.rb +131 -0
- data/lib/barometer/data/forecast.rb +66 -0
- data/lib/barometer/data/geo.rb +98 -0
- data/lib/barometer/data/location.rb +20 -0
- data/lib/barometer/data/measurement.rb +161 -0
- data/lib/barometer/data/pressure.rb +133 -0
- data/lib/barometer/data/speed.rb +147 -0
- data/lib/barometer/data/sun.rb +35 -0
- data/lib/barometer/data/temperature.rb +164 -0
- data/lib/barometer/data/units.rb +55 -0
- data/lib/barometer/data/zone.rb +124 -0
- data/lib/barometer/data.rb +15 -0
- data/lib/barometer/extensions/graticule.rb +50 -0
- data/lib/barometer/extensions/httparty.rb +21 -0
- data/lib/barometer/query.rb +228 -0
- data/lib/barometer/services/google.rb +146 -0
- data/lib/barometer/services/noaa.rb +6 -0
- data/lib/barometer/services/service.rb +324 -0
- data/lib/barometer/services/weather_bug.rb +6 -0
- data/lib/barometer/services/weather_dot_com.rb +6 -0
- data/lib/barometer/services/wunderground.rb +285 -0
- data/lib/barometer/services/yahoo.rb +274 -0
- data/lib/barometer/services.rb +6 -0
- data/lib/barometer/weather.rb +187 -0
- data/lib/barometer.rb +52 -0
- data/spec/barometer_spec.rb +162 -0
- data/spec/data_current_spec.rb +225 -0
- data/spec/data_distance_spec.rb +336 -0
- data/spec/data_forecast_spec.rb +150 -0
- data/spec/data_geo_spec.rb +90 -0
- data/spec/data_location_spec.rb +59 -0
- data/spec/data_measurement_spec.rb +411 -0
- data/spec/data_pressure_spec.rb +336 -0
- data/spec/data_speed_spec.rb +374 -0
- data/spec/data_sun_spec.rb +76 -0
- data/spec/data_temperature_spec.rb +396 -0
- data/spec/data_zone_spec.rb +133 -0
- data/spec/fixtures/current_calgary_ab.xml +1 -0
- data/spec/fixtures/forecast_calgary_ab.xml +1 -0
- data/spec/fixtures/geocode_40_73.xml +1 -0
- data/spec/fixtures/geocode_90210.xml +1 -0
- data/spec/fixtures/geocode_T5B4M9.xml +1 -0
- data/spec/fixtures/geocode_calgary_ab.xml +1 -0
- data/spec/fixtures/geocode_newyork_ny.xml +1 -0
- data/spec/fixtures/google_calgary_ab.xml +1 -0
- data/spec/fixtures/yahoo_90210.xml +1 -0
- data/spec/query_spec.rb +469 -0
- data/spec/service_google_spec.rb +144 -0
- data/spec/service_wunderground_spec.rb +330 -0
- data/spec/service_yahoo_spec.rb +299 -0
- data/spec/services_spec.rb +1106 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/units_spec.rb +101 -0
- data/spec/weather_spec.rb +265 -0
- metadata +119 -0
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <title>Yahoo! Weather - Beverly Hills, CA</title> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/90210_c.html</link> <description>Yahoo! Weather for Beverly Hills, CA</description> <language>en-us</language> <lastBuildDate>Sun, 26 Apr 2009 10:51 am PDT</lastBuildDate> <ttl>60</ttl> <yweather:location city="Beverly Hills" region="CA" country="US"/> <yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/> <yweather:wind chill="17" direction="0" speed="4.83" /> <yweather:atmosphere humidity="50" visibility="16.09" pressure="1017" rising="0" /> <yweather:astronomy sunrise="6:09 am" sunset="7:34 pm"/> <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url> </image> <item> <title>Conditions for Beverly Hills, CA at 10:51 am PDT</title> <geo:lat>34.08</geo:lat> <geo:long>-118.4</geo:long> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/90210_c.html</link> <pubDate>Sun, 26 Apr 2009 10:51 am PDT</pubDate> <yweather:condition text="Partly Cloudy" code="30" temp="17" date="Sun, 26 Apr 2009 10:51 am PDT" /> <description><![CDATA[ <img src="http://l.yimg.com/a/i/us/we/52/30.gif"/><br /> <b>Current Conditions:</b><br /> Partly Cloudy, 17 C<BR /> <BR /><b>Forecast:</b><BR /> Sun - Mostly Sunny. High: 19 Low: 11<br /> Mon - Cloudy. High: 18 Low: 11<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/USCA0090_c.html">Full Forecast at Yahoo! Weather</a><BR/> (provided by The Weather Channel)<br/> ]]></description> <yweather:forecast day="Sun" date="26 Apr 2009" low="11" high="19" text="Mostly Sunny" code="34" /> <yweather:forecast day="Mon" date="27 Apr 2009" low="11" high="18" text="Cloudy" code="26" /> <guid isPermaLink="false">90210_2009_04_26_10_51_PDT</guid> </item> </channel> </rss><!-- api2.weather.sp1.yahoo.com compressed/chunked Sun Apr 26 11:25:45 PDT 2009 -->
|
data/spec/query_spec.rb
ADDED
@@ -0,0 +1,469 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@zipcode = "90210"
|
7
|
+
@postal_code = "T5B 4M9"
|
8
|
+
@coordinates = "40.756054,-73.986951"
|
9
|
+
@geocode = "New York, NY"
|
10
|
+
|
11
|
+
# actual conversions
|
12
|
+
@zipcode_to_coordinates = "34.1030032,-118.4104684"
|
13
|
+
@zipcode_to_geocode = "Beverly Hills, CA, USA"
|
14
|
+
@postalcode_to_coordinates = "53.570447,-113.456083"
|
15
|
+
@geocode_to_coordinates = "40.756054,-73.986951"
|
16
|
+
@coordinates_to_geocode = "New York, NY, USA"
|
17
|
+
|
18
|
+
Barometer.google_geocode_key = nil
|
19
|
+
Barometer::Query.google_geocode_key = nil
|
20
|
+
#Barometer.skip_graticule = true
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the class methods" do
|
24
|
+
|
25
|
+
it "detects a zipcode" do
|
26
|
+
Barometer::Query.is_us_zipcode?(@zipcode).should be_true
|
27
|
+
Barometer::Query.is_us_zipcode?(@postal_code).should be_false
|
28
|
+
Barometer::Query.is_us_zipcode?(@coordinates).should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "detects a postalcode" do
|
32
|
+
Barometer::Query.is_canadian_postcode?(@postal_code).should be_true
|
33
|
+
Barometer::Query.is_canadian_postcode?(@zipcode).should be_false
|
34
|
+
Barometer::Query.is_canadian_postcode?(@coordinates).should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "detects a coordinates" do
|
38
|
+
Barometer::Query.is_coordinates?(@coordinates).should be_true
|
39
|
+
Barometer::Query.is_coordinates?(@zipcode).should be_false
|
40
|
+
Barometer::Query.is_coordinates?(@postal_code).should be_false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "determines the query format" do
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@query = Barometer::Query.new
|
49
|
+
@query.country_code.should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "recognizes a zip code" do
|
53
|
+
@query.q = @zipcode
|
54
|
+
@query.format.should be_nil
|
55
|
+
@query.analyze!
|
56
|
+
@query.format.to_sym.should == :zipcode
|
57
|
+
|
58
|
+
@query.country_code.should == "US"
|
59
|
+
@query.zipcode?.should be_true
|
60
|
+
@query.postalcode?.should be_false
|
61
|
+
@query.coordinates?.should be_false
|
62
|
+
@query.geocode?.should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "recognizes a postal code" do
|
66
|
+
@query.q = @postal_code
|
67
|
+
@query.format.should be_nil
|
68
|
+
@query.analyze!
|
69
|
+
@query.format.to_sym.should == :postalcode
|
70
|
+
|
71
|
+
@query.country_code.should == "CA"
|
72
|
+
@query.zipcode?.should be_false
|
73
|
+
@query.postalcode?.should be_true
|
74
|
+
@query.coordinates?.should be_false
|
75
|
+
@query.geocode?.should be_false
|
76
|
+
end
|
77
|
+
|
78
|
+
it "recognizes latitude/longitude" do
|
79
|
+
@query.q = @coordinates
|
80
|
+
@query.format.should be_nil
|
81
|
+
@query.analyze!
|
82
|
+
@query.format.to_sym.should == :coordinates
|
83
|
+
|
84
|
+
@query.country_code.should be_nil
|
85
|
+
@query.zipcode?.should be_false
|
86
|
+
@query.postalcode?.should be_false
|
87
|
+
@query.coordinates?.should be_true
|
88
|
+
@query.geocode?.should be_false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "defaults to a general geo_location" do
|
92
|
+
@query.q = @geocode
|
93
|
+
@query.format.should be_nil
|
94
|
+
@query.analyze!
|
95
|
+
@query.format.to_sym.should == :geocode
|
96
|
+
|
97
|
+
@query.country_code.should be_nil
|
98
|
+
@query.zipcode?.should be_false
|
99
|
+
@query.postalcode?.should be_false
|
100
|
+
@query.coordinates?.should be_false
|
101
|
+
@query.geocode?.should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "when initialized" do
|
107
|
+
|
108
|
+
before(:each) do
|
109
|
+
@query = Barometer::Query.new
|
110
|
+
end
|
111
|
+
|
112
|
+
it "responds to q" do
|
113
|
+
@query.q.should be_nil
|
114
|
+
end
|
115
|
+
|
116
|
+
# it "responds to geo" do
|
117
|
+
# @query.geo.should be_nil
|
118
|
+
# end
|
119
|
+
|
120
|
+
it "responds to format" do
|
121
|
+
@query.format.should be_nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "responds to country_code" do
|
125
|
+
@query.country_code.should be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
it "sets the query" do
|
129
|
+
query = Barometer::Query.new(@geocode)
|
130
|
+
query.q.should == @geocode
|
131
|
+
end
|
132
|
+
|
133
|
+
it "determines the format" do
|
134
|
+
query = Barometer::Query.new(@geocode)
|
135
|
+
query.format.should_not be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it "responds to google_api_key" do
|
139
|
+
Barometer::Query.google_geocode_key.should be_nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it "sets the google_api_key" do
|
143
|
+
key = "KEY"
|
144
|
+
Barometer::Query.google_geocode_key = key
|
145
|
+
Barometer::Query.google_geocode_key.should == key
|
146
|
+
end
|
147
|
+
|
148
|
+
it "defaults to the Module geocode key" do
|
149
|
+
key = "KEY"
|
150
|
+
Barometer::Query.google_geocode_key.should be_nil
|
151
|
+
Barometer.google_geocode_key = key
|
152
|
+
Barometer::Query.google_geocode_key.should == key
|
153
|
+
end
|
154
|
+
|
155
|
+
it "responds to preferred" do
|
156
|
+
@query.preferred.should be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it "responds to geo" do
|
160
|
+
@query.geo.should be_nil
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
use_graticule = true
|
166
|
+
|
167
|
+
if use_graticule
|
168
|
+
describe "when converting queries" do
|
169
|
+
|
170
|
+
before(:each) do
|
171
|
+
@key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
172
|
+
url_start = "http://maps.google.com/maps/geo?"
|
173
|
+
#
|
174
|
+
# for Graticule and/or HTTParty geocoding
|
175
|
+
#
|
176
|
+
FakeWeb.register_uri(:get,
|
177
|
+
"#{url_start}gl=US&key=#{@key}&output=xml&q=90210",
|
178
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
179
|
+
'fixtures',
|
180
|
+
'geocode_90210.xml')
|
181
|
+
)
|
182
|
+
)
|
183
|
+
FakeWeb.register_uri(:get,
|
184
|
+
"#{url_start}gl=CA&key=#{@key}&output=xml&q=T5B%204M9",
|
185
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
186
|
+
'fixtures',
|
187
|
+
'geocode_T5B4M9.xml')
|
188
|
+
)
|
189
|
+
)
|
190
|
+
#
|
191
|
+
# for Graticule geocoding
|
192
|
+
#
|
193
|
+
FakeWeb.register_uri(:get,
|
194
|
+
"#{url_start}gl=&key=#{@key}&output=xml&q=New%20York,%20NY",
|
195
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
196
|
+
'fixtures',
|
197
|
+
'geocode_newyork_ny.xml')
|
198
|
+
)
|
199
|
+
)
|
200
|
+
FakeWeb.register_uri(:get,
|
201
|
+
"#{url_start}gl=&key=#{@key}&output=xml&q=40.756054,-73.986951",
|
202
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
203
|
+
'fixtures',
|
204
|
+
'geocode_40_73.xml')
|
205
|
+
)
|
206
|
+
)
|
207
|
+
#
|
208
|
+
# for HTTParty geocoding
|
209
|
+
#
|
210
|
+
FakeWeb.register_uri(:get,
|
211
|
+
"#{url_start}output=xml&q=New%20York%2C%20NY&gl=&key=#{@key}",
|
212
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
213
|
+
'fixtures',
|
214
|
+
'geocode_newyork_ny.xml')
|
215
|
+
)
|
216
|
+
)
|
217
|
+
FakeWeb.register_uri(:get,
|
218
|
+
"#{url_start}gl=&output=xml&q=#{CGI.escape("40.756054,-73.986951")}&key=#{@key}",
|
219
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
220
|
+
'fixtures',
|
221
|
+
'geocode_40_73.xml')
|
222
|
+
)
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "to coordinates," do
|
227
|
+
|
228
|
+
before(:each) do
|
229
|
+
Barometer::Query.google_geocode_key = @key
|
230
|
+
end
|
231
|
+
|
232
|
+
it "skips conversion unless Graticule enabled or no API key" do
|
233
|
+
Barometer::Query.google_geocode_key = nil
|
234
|
+
Barometer::Query.google_geocode_key.should be_nil
|
235
|
+
Barometer.google_geocode_key = nil
|
236
|
+
Barometer.google_geocode_key.should be_nil
|
237
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).should be_nil
|
238
|
+
end
|
239
|
+
|
240
|
+
it "attempts conversion if Graticule enabled and has API key" do
|
241
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).should_not be_nil
|
242
|
+
end
|
243
|
+
|
244
|
+
it "converts from geocode" do
|
245
|
+
Barometer::Query.to_coordinates(@geocode, :geocode).first.should == "40.756054,-73.986951"
|
246
|
+
end
|
247
|
+
|
248
|
+
it "converts from zipcode" do
|
249
|
+
Barometer::Query.to_coordinates(@zipcode, :zipcode).first.should == "34.1030032,-118.4104684"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "converts from postalcode" do
|
253
|
+
Barometer::Query.to_coordinates(@postal_code, :postalcode).first.should == "53.570447,-113.456083"
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "to geocode" do
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
Barometer::Query.google_geocode_key = @key
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "when Graticule enabled," do
|
265
|
+
|
266
|
+
it "converts from coordinates" do
|
267
|
+
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == "New York, NY, USA"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "converts from zipcode" do
|
271
|
+
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == "Beverly Hills, CA, USA"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "converts from postalcode" do
|
275
|
+
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "when Graticule disabled," do
|
281
|
+
|
282
|
+
it "uses coordinates" do
|
283
|
+
Barometer::Query.google_geocode_key = nil
|
284
|
+
Barometer::Query.google_geocode_key.should be_nil
|
285
|
+
Barometer.google_geocode_key = nil
|
286
|
+
Barometer.google_geocode_key.should be_nil
|
287
|
+
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == @coordinates
|
288
|
+
end
|
289
|
+
|
290
|
+
it "uses zipcode" do
|
291
|
+
Barometer::Query.google_geocode_key = nil
|
292
|
+
Barometer::Query.google_geocode_key.should be_nil
|
293
|
+
Barometer.google_geocode_key = nil
|
294
|
+
Barometer.google_geocode_key.should be_nil
|
295
|
+
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == @zipcode
|
296
|
+
end
|
297
|
+
|
298
|
+
it "uses postalcode" do
|
299
|
+
Barometer::Query.google_geocode_key = nil
|
300
|
+
Barometer::Query.google_geocode_key.should be_nil
|
301
|
+
Barometer.google_geocode_key = nil
|
302
|
+
Barometer.google_geocode_key.should be_nil
|
303
|
+
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "when returning the query to a Weather API" do
|
313
|
+
|
314
|
+
it "raises an error if there are NO acceptable formats" do
|
315
|
+
acceptable_formats = nil
|
316
|
+
query = Barometer::Query.new
|
317
|
+
lambda { query.convert!(acceptable_formats) }.should raise_error
|
318
|
+
|
319
|
+
acceptable_formats = []
|
320
|
+
lambda { query.convert!(acceptable_formats) }.should raise_error
|
321
|
+
end
|
322
|
+
|
323
|
+
describe "and the query is already of an acceptable format" do
|
324
|
+
|
325
|
+
before(:each) do
|
326
|
+
# all formats accepted
|
327
|
+
@acceptable_formats = [:zipcode, :postalcode, :geocode, :coordinates]
|
328
|
+
end
|
329
|
+
|
330
|
+
it "returns the zipcode untouched" do
|
331
|
+
query = Barometer::Query.new(@zipcode)
|
332
|
+
query.convert!(@acceptable_formats).should == @zipcode
|
333
|
+
query.country_code.should == "US"
|
334
|
+
end
|
335
|
+
|
336
|
+
it "returns the postalcode untouched" do
|
337
|
+
query = Barometer::Query.new(@postal_code)
|
338
|
+
query.convert!(@acceptable_formats).should == @postal_code
|
339
|
+
query.country_code.should == "CA"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "returns the coordinates untouched" do
|
343
|
+
query = Barometer::Query.new(@coordinates)
|
344
|
+
query.convert!(@acceptable_formats).should == @coordinates
|
345
|
+
end
|
346
|
+
|
347
|
+
it "returns the geocode untouched" do
|
348
|
+
query = Barometer::Query.new(@geocode)
|
349
|
+
query.convert!(@acceptable_formats).should == @geocode
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
describe "and the query needs converting" do
|
355
|
+
|
356
|
+
describe "with an intial format of :zipcode," do
|
357
|
+
|
358
|
+
before(:each) do
|
359
|
+
@query = Barometer::Query.new(@zipcode)
|
360
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
361
|
+
end
|
362
|
+
|
363
|
+
it "converts to coordinates" do
|
364
|
+
acceptable_formats = [:coordinates]
|
365
|
+
@query.convert!(acceptable_formats).should == @zipcode_to_coordinates
|
366
|
+
@query.country_code.should == "US"
|
367
|
+
end
|
368
|
+
|
369
|
+
it "converts to geocode" do
|
370
|
+
acceptable_formats = [:geocode]
|
371
|
+
@query.convert!(acceptable_formats).should == @zipcode_to_geocode
|
372
|
+
@query.country_code.should == "US"
|
373
|
+
end
|
374
|
+
|
375
|
+
it "skips converting to postalcode" do
|
376
|
+
acceptable_formats = [:postalcode]
|
377
|
+
@query.convert!(acceptable_formats).should be_nil
|
378
|
+
@query.country_code.should == "US"
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
describe "with an intial format of :postalcode," do
|
384
|
+
|
385
|
+
before(:each) do
|
386
|
+
@query = Barometer::Query.new(@postal_code)
|
387
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
388
|
+
end
|
389
|
+
|
390
|
+
it "converts to coordinates" do
|
391
|
+
acceptable_formats = [:coordinates]
|
392
|
+
@query.convert!(acceptable_formats).should == @postalcode_to_coordinates
|
393
|
+
@query.country_code.should == "CA"
|
394
|
+
end
|
395
|
+
|
396
|
+
it "skips converting to geocode" do
|
397
|
+
acceptable_formats = [:geocode]
|
398
|
+
@query.convert!(acceptable_formats).should == @postal_code
|
399
|
+
@query.country_code.should == "CA"
|
400
|
+
end
|
401
|
+
|
402
|
+
it "skips converting to zipcode" do
|
403
|
+
acceptable_formats = [:zipcode]
|
404
|
+
@query.convert!(acceptable_formats).should be_nil
|
405
|
+
@query.country_code.should == "CA"
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "with an intial format of :geocode," do
|
411
|
+
|
412
|
+
before(:each) do
|
413
|
+
@query = Barometer::Query.new(@geocode)
|
414
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
415
|
+
end
|
416
|
+
|
417
|
+
it "converts to coordinates" do
|
418
|
+
acceptable_formats = [:coordinates]
|
419
|
+
@query.convert!(acceptable_formats).should == @geocode_to_coordinates
|
420
|
+
@query.country_code.should == "US"
|
421
|
+
end
|
422
|
+
|
423
|
+
it "skips converting to zipcode" do
|
424
|
+
acceptable_formats = [:zipcode]
|
425
|
+
@query.convert!(acceptable_formats).should be_nil
|
426
|
+
@query.country_code.should be_nil
|
427
|
+
end
|
428
|
+
|
429
|
+
it "skips converting to postalcode" do
|
430
|
+
acceptable_formats = [:postalcode]
|
431
|
+
@query.convert!(acceptable_formats).should be_nil
|
432
|
+
@query.country_code.should be_nil
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
describe "with an intial format of :coordinates," do
|
438
|
+
|
439
|
+
before(:each) do
|
440
|
+
@query = Barometer::Query.new(@coordinates)
|
441
|
+
Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
|
442
|
+
end
|
443
|
+
|
444
|
+
it "converts to geocode" do
|
445
|
+
acceptable_formats = [:geocode]
|
446
|
+
@query.convert!(acceptable_formats).should == @coordinates_to_geocode
|
447
|
+
@query.country_code.should == "US"
|
448
|
+
end
|
449
|
+
|
450
|
+
it "skips converting to zipcode" do
|
451
|
+
acceptable_formats = [:zipcode]
|
452
|
+
@query.convert!(acceptable_formats).should be_nil
|
453
|
+
@query.country_code.should be_nil
|
454
|
+
end
|
455
|
+
|
456
|
+
it "skips converting to postalcode" do
|
457
|
+
acceptable_formats = [:postalcode]
|
458
|
+
@query.convert!(acceptable_formats).should be_nil
|
459
|
+
@query.country_code.should be_nil
|
460
|
+
end
|
461
|
+
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Google" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@accepted_formats = [:zipcode, :postalcode, :geocode]
|
7
|
+
@base_uri = "http://google.com"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "the class methods" do
|
11
|
+
|
12
|
+
it "defines accepted_formats" do
|
13
|
+
Barometer::Google.accepted_formats.should == @accepted_formats
|
14
|
+
end
|
15
|
+
|
16
|
+
# it "defines base_uri" do
|
17
|
+
# Barometer::Google.base_uri.should == @base_uri
|
18
|
+
# end
|
19
|
+
|
20
|
+
it "defines get_all" do
|
21
|
+
Barometer::Google.respond_to?("get_all").should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "building the current data" do
|
27
|
+
|
28
|
+
it "defines the build method" do
|
29
|
+
Barometer::Google.respond_to?("build_current").should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "requires Hash input" do
|
33
|
+
lambda { Barometer::Google.build_current }.should raise_error(ArgumentError)
|
34
|
+
lambda { Barometer::Google.build_current({}) }.should_not raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns Barometer::CurrentMeasurement object" do
|
38
|
+
current = Barometer::Google.build_current({})
|
39
|
+
current.is_a?(Barometer::CurrentMeasurement).should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "building the forecast data" do
|
45
|
+
|
46
|
+
it "defines the build method" do
|
47
|
+
Barometer::Google.respond_to?("build_forecast").should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "requires Hash input" do
|
51
|
+
lambda { Barometer::Google.build_forecast }.should raise_error(ArgumentError)
|
52
|
+
lambda { Barometer::Google.build_forecast({}) }.should_not raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns Array object" do
|
56
|
+
current = Barometer::Google.build_forecast({})
|
57
|
+
current.is_a?(Array).should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "building the location data" do
|
63
|
+
|
64
|
+
it "defines the build method" do
|
65
|
+
Barometer::Google.respond_to?("build_location").should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "requires Barometer::Geo input" do
|
69
|
+
geo = Barometer::Geo.new({})
|
70
|
+
lambda { Barometer::Google.build_location({}) }.should raise_error(ArgumentError)
|
71
|
+
lambda { Barometer::Google.build_location(geo) }.should_not raise_error(ArgumentError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns Barometer::Location object" do
|
75
|
+
geo = Barometer::Geo.new({})
|
76
|
+
location = Barometer::Google.build_location(geo)
|
77
|
+
location.is_a?(Barometer::Location).should be_true
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
# describe "building the timezone" do
|
83
|
+
#
|
84
|
+
# it "defines the build method" do
|
85
|
+
# Barometer::Google.respond_to?("build_timezone").should be_true
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# it "requires Hash input" do
|
89
|
+
# lambda { Barometer::Google.build_timezone }.should raise_error(ArgumentError)
|
90
|
+
# lambda { Barometer::Google.build_timezone({}) }.should_not raise_error(ArgumentError)
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# end
|
94
|
+
|
95
|
+
describe "when measuring" do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@query = Barometer::Query.new("Calgary,AB")
|
99
|
+
@query.preferred = "Calgary,AB"
|
100
|
+
@measurement = Barometer::Measurement.new
|
101
|
+
|
102
|
+
FakeWeb.register_uri(:get,
|
103
|
+
"http://google.com/ig/api?weather=#{CGI.escape(@query.preferred)}&hl=en-GB",
|
104
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
105
|
+
'fixtures',
|
106
|
+
'google_calgary_ab.xml')
|
107
|
+
)
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "all" do
|
112
|
+
|
113
|
+
it "responds to _measure" do
|
114
|
+
Barometer::Google.respond_to?("_measure").should be_true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "requires a Barometer::Measurement object" do
|
118
|
+
lambda { Barometer::Google._measure(nil, @query) }.should raise_error(ArgumentError)
|
119
|
+
lambda { Barometer::Google._measure("invlaid", @query) }.should raise_error(ArgumentError)
|
120
|
+
|
121
|
+
lambda { Barometer::Google._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "requires a Barometer::Query query" do
|
125
|
+
lambda { Barometer::Google._measure }.should raise_error(ArgumentError)
|
126
|
+
lambda { Barometer::Google._measure(@measurement, 1) }.should raise_error(ArgumentError)
|
127
|
+
|
128
|
+
lambda { Barometer::Google._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "returns a Barometer::Measurement object" do
|
132
|
+
result = Barometer::Google._measure(@measurement, @query)
|
133
|
+
result.is_a?(Barometer::Measurement).should be_true
|
134
|
+
result.current.is_a?(Barometer::CurrentMeasurement).should be_true
|
135
|
+
result.forecast.is_a?(Array).should be_true
|
136
|
+
|
137
|
+
result.source.should == :google
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|