gcoder 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe GCoder::Storage::Adapter do
4
+ it 'shoyld raise an error if instantiated directly' do
5
+ -> { GCoder::Storage::Adapter.new }.must_raise GCoder::NotImplementedError
6
+ end
7
+ end
8
+
9
+ describe GCoder::Storage::HeapAdapter do
10
+ before do
11
+ @db = GCoder::Storage[:heap].new
12
+ end
13
+
14
+ after do
15
+ @db.clear
16
+ end
17
+
18
+ it 'should be able to get values that were previously set' do
19
+ @db.set('1 a', 'test_1')
20
+ @db.set('2 b', 'test_2')
21
+ @db.set('3 c', 'test_3')
22
+ @db.get('1 a').must_equal 'test_1'
23
+ @db.get('2 b').must_equal 'test_2'
24
+ @db.get('3 c').must_equal 'test_3'
25
+ end
26
+
27
+ it 'should remove all keys from the heap' do
28
+ @db.set('1 a', 'test_1')
29
+ @db.set('2 b', 'test_2')
30
+ @db.set('3 c', 'test_3')
31
+ @db.clear
32
+ @db.get('1 a').must_be_nil
33
+ @db.get('2 b').must_be_nil
34
+ @db.get('3 c').must_be_nil
35
+ end
36
+ end
37
+
38
+ describe GCoder::Storage::RedisAdapter do
39
+ before do
40
+ @db = GCoder::Storage[:redis].new
41
+ end
42
+
43
+ after do
44
+ @db.clear
45
+ end
46
+
47
+ it 'should be able to get values that were previously set' do
48
+ @db.set('1 a', 'test_1')
49
+ @db.set('2 b', 'test_2')
50
+ @db.set('3 c', 'test_3')
51
+ @db.get('1 a').must_equal 'test_1'
52
+ @db.get('2 b').must_equal 'test_2'
53
+ @db.get('3 c').must_equal 'test_3'
54
+ end
55
+
56
+ it 'should remove all keys from the heap' do
57
+ @db.set('1 a', 'test_1')
58
+ @db.set('2 b', 'test_2')
59
+ @db.set('3 c', 'test_3')
60
+ @db.clear
61
+ @db.get('1').must_be_nil
62
+ @db.get('2').must_be_nil
63
+ @db.get('3').must_be_nil
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe GCoder do
4
+ describe '::connect' do
5
+
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'minitest/spec'
2
+ require 'gcoder'
3
+ require 'yaml'
4
+
5
+ MiniTest::Unit.autorun
6
+
7
+ unless defined? SpecHelper
8
+ module SpecHelper
9
+ YAML.load_file('spec/support/requests.yml').each do |stub|
10
+ body = File.read("spec/support/requests/#{stub[:file]}")
11
+ GCoder::Geocoder::Request.stub(stub[:uri], body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,96 @@
1
+ {
2
+ "status": "OK",
3
+ "results": [ {
4
+ "types": [ "intersection" ],
5
+ "formatted_address": "Spadina Ave & Queen St W, Toronto, ON M5V, Canada",
6
+ "address_components": [ {
7
+ "long_name": "Spadina Ave",
8
+ "short_name": "Spadina Ave",
9
+ "types": [ "route" ]
10
+ }, {
11
+ "long_name": "Toronto",
12
+ "short_name": "Toronto",
13
+ "types": [ "locality", "political" ]
14
+ }, {
15
+ "long_name": "Toronto Division",
16
+ "short_name": "Toronto Division",
17
+ "types": [ "administrative_area_level_2", "political" ]
18
+ }, {
19
+ "long_name": "Ontario",
20
+ "short_name": "ON",
21
+ "types": [ "administrative_area_level_1", "political" ]
22
+ }, {
23
+ "long_name": "Canada",
24
+ "short_name": "CA",
25
+ "types": [ "country", "political" ]
26
+ }, {
27
+ "long_name": "M5V",
28
+ "short_name": "M5V",
29
+ "types": [ "postal_code" ]
30
+ } ],
31
+ "geometry": {
32
+ "location": {
33
+ "lat": 43.6487606,
34
+ "lng": -79.3962415
35
+ },
36
+ "location_type": "APPROXIMATE",
37
+ "viewport": {
38
+ "southwest": {
39
+ "lat": 43.6456130,
40
+ "lng": -79.3993891
41
+ },
42
+ "northeast": {
43
+ "lat": 43.6519082,
44
+ "lng": -79.3930939
45
+ }
46
+ }
47
+ },
48
+ "partial_match": true
49
+ }, {
50
+ "types": [ "intersection" ],
51
+ "formatted_address": "Spadina Crescent E & Queen St, Saskatoon, SK S7K 0N2, Canada",
52
+ "address_components": [ {
53
+ "long_name": "Spadina Crescent E",
54
+ "short_name": "Spadina Crescent E",
55
+ "types": [ "route" ]
56
+ }, {
57
+ "long_name": "Saskatoon",
58
+ "short_name": "Saskatoon",
59
+ "types": [ "locality", "political" ]
60
+ }, {
61
+ "long_name": "Division No. 11",
62
+ "short_name": "Division No. 11",
63
+ "types": [ "administrative_area_level_2", "political" ]
64
+ }, {
65
+ "long_name": "Saskatchewan",
66
+ "short_name": "SK",
67
+ "types": [ "administrative_area_level_1", "political" ]
68
+ }, {
69
+ "long_name": "Canada",
70
+ "short_name": "CA",
71
+ "types": [ "country", "political" ]
72
+ }, {
73
+ "long_name": "S7K 0N2",
74
+ "short_name": "S7K 0N2",
75
+ "types": [ "postal_code" ]
76
+ } ],
77
+ "geometry": {
78
+ "location": {
79
+ "lat": 52.1365667,
80
+ "lng": -106.6474145
81
+ },
82
+ "location_type": "APPROXIMATE",
83
+ "viewport": {
84
+ "southwest": {
85
+ "lat": 52.1334191,
86
+ "lng": -106.6505621
87
+ },
88
+ "northeast": {
89
+ "lat": 52.1397143,
90
+ "lng": -106.6442669
91
+ }
92
+ }
93
+ },
94
+ "partial_match": true
95
+ } ]
96
+ }
@@ -0,0 +1,364 @@
1
+ {
2
+ "status": "OK",
3
+ "results": [ {
4
+ "types": [ "street_address" ],
5
+ "formatted_address": "378 Queen St W, Toronto, ON M5V 2A5, Canada",
6
+ "address_components": [ {
7
+ "long_name": "378",
8
+ "short_name": "378",
9
+ "types": [ "street_number" ]
10
+ }, {
11
+ "long_name": "Queen St W",
12
+ "short_name": "Queen St W",
13
+ "types": [ "route" ]
14
+ }, {
15
+ "long_name": "Toronto",
16
+ "short_name": "Toronto",
17
+ "types": [ "locality", "political" ]
18
+ }, {
19
+ "long_name": "Toronto Division",
20
+ "short_name": "Toronto Division",
21
+ "types": [ "administrative_area_level_2", "political" ]
22
+ }, {
23
+ "long_name": "Ontario",
24
+ "short_name": "ON",
25
+ "types": [ "administrative_area_level_1", "political" ]
26
+ }, {
27
+ "long_name": "Canada",
28
+ "short_name": "CA",
29
+ "types": [ "country", "political" ]
30
+ }, {
31
+ "long_name": "M5V 2A5",
32
+ "short_name": "M5V 2A5",
33
+ "types": [ "postal_code" ]
34
+ } ],
35
+ "geometry": {
36
+ "location": {
37
+ "lat": 43.6489064,
38
+ "lng": -79.3962669
39
+ },
40
+ "location_type": "ROOFTOP",
41
+ "viewport": {
42
+ "southwest": {
43
+ "lat": 43.6457588,
44
+ "lng": -79.3994145
45
+ },
46
+ "northeast": {
47
+ "lat": 43.6520540,
48
+ "lng": -79.3931193
49
+ }
50
+ }
51
+ }
52
+ }, {
53
+ "types": [ "postal_code" ],
54
+ "formatted_address": "Toronto, ON M5V 0A5, Canada",
55
+ "address_components": [ {
56
+ "long_name": "M5V 0A5",
57
+ "short_name": "M5V 0A5",
58
+ "types": [ "postal_code" ]
59
+ }, {
60
+ "long_name": "Toronto",
61
+ "short_name": "Toronto",
62
+ "types": [ "locality", "political" ]
63
+ }, {
64
+ "long_name": "Toronto Division",
65
+ "short_name": "Toronto Division",
66
+ "types": [ "administrative_area_level_2", "political" ]
67
+ }, {
68
+ "long_name": "Ontario",
69
+ "short_name": "ON",
70
+ "types": [ "administrative_area_level_1", "political" ]
71
+ }, {
72
+ "long_name": "Canada",
73
+ "short_name": "CA",
74
+ "types": [ "country", "political" ]
75
+ } ],
76
+ "geometry": {
77
+ "location": {
78
+ "lat": 43.6475910,
79
+ "lng": -79.3923810
80
+ },
81
+ "location_type": "APPROXIMATE",
82
+ "viewport": {
83
+ "southwest": {
84
+ "lat": 43.6444434,
85
+ "lng": -79.3955286
86
+ },
87
+ "northeast": {
88
+ "lat": 43.6507386,
89
+ "lng": -79.3892334
90
+ }
91
+ }
92
+ }
93
+ }, {
94
+ "types": [ "postal_code" ],
95
+ "formatted_address": "Toronto, ON M5V 1A1, Canada",
96
+ "address_components": [ {
97
+ "long_name": "M5V",
98
+ "short_name": "M5V",
99
+ "types": [ "postal_code" ]
100
+ }, {
101
+ "long_name": "Toronto",
102
+ "short_name": "Toronto",
103
+ "types": [ "locality", "political" ]
104
+ }, {
105
+ "long_name": "Toronto Division",
106
+ "short_name": "Toronto Division",
107
+ "types": [ "administrative_area_level_2", "political" ]
108
+ }, {
109
+ "long_name": "Ontario",
110
+ "short_name": "ON",
111
+ "types": [ "administrative_area_level_1", "political" ]
112
+ }, {
113
+ "long_name": "Canada",
114
+ "short_name": "CA",
115
+ "types": [ "country", "political" ]
116
+ }, {
117
+ "long_name": "M5V 1A1",
118
+ "short_name": "M5V 1A1",
119
+ "types": [ "postal_code" ]
120
+ } ],
121
+ "geometry": {
122
+ "location": {
123
+ "lat": 43.6289467,
124
+ "lng": -79.3944199
125
+ },
126
+ "location_type": "APPROXIMATE",
127
+ "viewport": {
128
+ "southwest": {
129
+ "lat": 43.6118009,
130
+ "lng": -79.4141832
131
+ },
132
+ "northeast": {
133
+ "lat": 43.6510137,
134
+ "lng": -79.3740776
135
+ }
136
+ },
137
+ "bounds": {
138
+ "southwest": {
139
+ "lat": 43.6118009,
140
+ "lng": -79.4141832
141
+ },
142
+ "northeast": {
143
+ "lat": 43.6510137,
144
+ "lng": -79.3740776
145
+ }
146
+ }
147
+ }
148
+ }, {
149
+ "types": [ "neighborhood", "political" ],
150
+ "formatted_address": "Queen Street West, Toronto, ON, Canada",
151
+ "address_components": [ {
152
+ "long_name": "Queen Street West",
153
+ "short_name": "Queen Street West",
154
+ "types": [ "neighborhood", "political" ]
155
+ }, {
156
+ "long_name": "Toronto",
157
+ "short_name": "Toronto",
158
+ "types": [ "locality", "political" ]
159
+ }, {
160
+ "long_name": "Toronto",
161
+ "short_name": "Toronto",
162
+ "types": [ "administrative_area_level_2", "political" ]
163
+ }, {
164
+ "long_name": "Ontario",
165
+ "short_name": "ON",
166
+ "types": [ "administrative_area_level_1", "political" ]
167
+ }, {
168
+ "long_name": "Canada",
169
+ "short_name": "CA",
170
+ "types": [ "country", "political" ]
171
+ } ],
172
+ "geometry": {
173
+ "location": {
174
+ "lat": 43.6405312,
175
+ "lng": -79.4422593
176
+ },
177
+ "location_type": "APPROXIMATE",
178
+ "viewport": {
179
+ "southwest": {
180
+ "lat": 43.6296630,
181
+ "lng": -79.4919690
182
+ },
183
+ "northeast": {
184
+ "lat": 43.6613770,
185
+ "lng": -79.3612400
186
+ }
187
+ },
188
+ "bounds": {
189
+ "southwest": {
190
+ "lat": 43.6296630,
191
+ "lng": -79.4919690
192
+ },
193
+ "northeast": {
194
+ "lat": 43.6613770,
195
+ "lng": -79.3612400
196
+ }
197
+ }
198
+ }
199
+ }, {
200
+ "types": [ "administrative_area_level_2", "political" ],
201
+ "formatted_address": "Toronto Division, Ontario, Canada",
202
+ "address_components": [ {
203
+ "long_name": "Toronto Division",
204
+ "short_name": "Toronto Division",
205
+ "types": [ "administrative_area_level_2", "political" ]
206
+ }, {
207
+ "long_name": "Ontario",
208
+ "short_name": "ON",
209
+ "types": [ "administrative_area_level_1", "political" ]
210
+ }, {
211
+ "long_name": "Canada",
212
+ "short_name": "CA",
213
+ "types": [ "country", "political" ]
214
+ } ],
215
+ "geometry": {
216
+ "location": {
217
+ "lat": 43.6689775,
218
+ "lng": -79.2902133
219
+ },
220
+ "location_type": "APPROXIMATE",
221
+ "viewport": {
222
+ "southwest": {
223
+ "lat": 43.4582970,
224
+ "lng": -79.6392190
225
+ },
226
+ "northeast": {
227
+ "lat": 43.8554580,
228
+ "lng": -79.0024810
229
+ }
230
+ },
231
+ "bounds": {
232
+ "southwest": {
233
+ "lat": 43.4582970,
234
+ "lng": -79.6392190
235
+ },
236
+ "northeast": {
237
+ "lat": 43.8554580,
238
+ "lng": -79.0024810
239
+ }
240
+ }
241
+ }
242
+ }, {
243
+ "types": [ "locality", "political" ],
244
+ "formatted_address": "Toronto, ON, Canada",
245
+ "address_components": [ {
246
+ "long_name": "Toronto",
247
+ "short_name": "Toronto",
248
+ "types": [ "locality", "political" ]
249
+ }, {
250
+ "long_name": "Toronto Division",
251
+ "short_name": "Toronto Division",
252
+ "types": [ "administrative_area_level_2", "political" ]
253
+ }, {
254
+ "long_name": "Ontario",
255
+ "short_name": "ON",
256
+ "types": [ "administrative_area_level_1", "political" ]
257
+ }, {
258
+ "long_name": "Canada",
259
+ "short_name": "CA",
260
+ "types": [ "country", "political" ]
261
+ } ],
262
+ "geometry": {
263
+ "location": {
264
+ "lat": 43.6525000,
265
+ "lng": -79.3816667
266
+ },
267
+ "location_type": "APPROXIMATE",
268
+ "viewport": {
269
+ "southwest": {
270
+ "lat": 43.4582970,
271
+ "lng": -79.6392190
272
+ },
273
+ "northeast": {
274
+ "lat": 43.8554580,
275
+ "lng": -79.0024810
276
+ }
277
+ },
278
+ "bounds": {
279
+ "southwest": {
280
+ "lat": 43.4582970,
281
+ "lng": -79.6392190
282
+ },
283
+ "northeast": {
284
+ "lat": 43.8554580,
285
+ "lng": -79.0024810
286
+ }
287
+ }
288
+ }
289
+ }, {
290
+ "types": [ "administrative_area_level_1", "political" ],
291
+ "formatted_address": "Ontario, Canada",
292
+ "address_components": [ {
293
+ "long_name": "Ontario",
294
+ "short_name": "ON",
295
+ "types": [ "administrative_area_level_1", "political" ]
296
+ }, {
297
+ "long_name": "Canada",
298
+ "short_name": "CA",
299
+ "types": [ "country", "political" ]
300
+ } ],
301
+ "geometry": {
302
+ "location": {
303
+ "lat": 51.2537750,
304
+ "lng": -85.3232139
305
+ },
306
+ "location_type": "APPROXIMATE",
307
+ "viewport": {
308
+ "southwest": {
309
+ "lat": 41.6765560,
310
+ "lng": -95.1562270
311
+ },
312
+ "northeast": {
313
+ "lat": 56.9313930,
314
+ "lng": -74.3206480
315
+ }
316
+ },
317
+ "bounds": {
318
+ "southwest": {
319
+ "lat": 41.6765560,
320
+ "lng": -95.1562270
321
+ },
322
+ "northeast": {
323
+ "lat": 56.9313930,
324
+ "lng": -74.3206480
325
+ }
326
+ }
327
+ }
328
+ }, {
329
+ "types": [ "country", "political" ],
330
+ "formatted_address": "Canada",
331
+ "address_components": [ {
332
+ "long_name": "Canada",
333
+ "short_name": "CA",
334
+ "types": [ "country", "political" ]
335
+ } ],
336
+ "geometry": {
337
+ "location": {
338
+ "lat": 56.1303660,
339
+ "lng": -106.3467710
340
+ },
341
+ "location_type": "APPROXIMATE",
342
+ "viewport": {
343
+ "southwest": {
344
+ "lat": 41.6763279,
345
+ "lng": -141.0027250
346
+ },
347
+ "northeast": {
348
+ "lat": 83.6381000,
349
+ "lng": -50.9766000
350
+ }
351
+ },
352
+ "bounds": {
353
+ "southwest": {
354
+ "lat": 41.6763279,
355
+ "lng": -141.0027250
356
+ },
357
+ "northeast": {
358
+ "lat": 83.6381000,
359
+ "lng": -50.9766000
360
+ }
361
+ }
362
+ }
363
+ } ]
364
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "ZERO_RESULTS",
3
+ "results": [ ]
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "REQUEST_DENIED",
3
+ "results": [ ]
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "OVER_QUERY_LIMIT",
3
+ "results": [ ]
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "INVALID_REQUEST",
3
+ "results": [ ]
4
+ }
@@ -0,0 +1,18 @@
1
+ ---
2
+ - :file: 1.json
3
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=queen+and+spadina&region=ca
4
+
5
+ - :file: 2.json
6
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=43.6487606%2C-79.3962415
7
+
8
+ - :file: 3.json
9
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=noresults
10
+
11
+ - :file: 4.json
12
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=denied
13
+
14
+ - :file: 5.json
15
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=overlimit
16
+
17
+ - :file: 6.json
18
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=invalid