go_maps 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .DS_Store
2
+ *.tmproj
3
+ tmtags
4
+ *~
5
+ \#*
6
+ .\#*
7
+ *.swp
8
+ coverage
9
+ rdoc
10
+ pkg
11
+ tags
data/README.markdown ADDED
@@ -0,0 +1,28 @@
1
+ ## ABOUT
2
+
3
+ Easy way to get the distance between two addresses (by car)
4
+
5
+ ## LICENSE
6
+
7
+ (The MIT License)
8
+
9
+ Copyright © 2010
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ ‘Software’), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be
20
+ included in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "go_maps"
8
+ gem.version = "0.1.0"
9
+ gem.summary = %Q{Ruby API to geographic operations}
10
+ gem.description = %Q{Ruby API to geographic operations}
11
+ gem.homepage = "http://github.com/gonow/go_maps"
12
+ gem.authors = ["Gonow"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
15
+ gem.add_dependency("crack", ">= 0.1.6")
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "go_maps #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
@@ -0,0 +1,33 @@
1
+ module GoMaps
2
+ class Address
3
+ def initialize(address)
4
+ @address = address
5
+ end
6
+
7
+ def exists?
8
+ location['status'] == 'OK'
9
+ end
10
+
11
+ def distance_to(address)
12
+ directions_to(address)['routes'].first['legs'].first['distance']['text'].gsub(' km', '').gsub(',', '.').to_f rescue raise AddressNotFoundException
13
+ end
14
+
15
+ private
16
+
17
+ def directions_to(address)
18
+ api_response :directions, "origin=#{@address}&destination=#{address}"
19
+ end
20
+
21
+ def location
22
+ api_response :geocode, "address=#{@address}"
23
+ end
24
+
25
+ def api_response(api, query_string)
26
+ Crack::JSON.parse open(URI.escape(url_for(api) + query_string)).read
27
+ end
28
+
29
+ def url_for(api)
30
+ "http://maps.google.com/maps/api/#{api}/json?sensor=false&language=pt-BR&"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module GoMaps
2
+ class AddressNotFoundException < RuntimeError
3
+ end
4
+ end
5
+
data/lib/go_maps.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'crack'
2
+ require 'open-uri'
3
+ require 'go_maps/address'
4
+ require 'go_maps/address_not_found_exception'
@@ -0,0 +1,5 @@
1
+ {
2
+ "status": "ZERO_RESULTS",
3
+ "results": [ ]
4
+ }
5
+
@@ -0,0 +1,356 @@
1
+ {
2
+ "status": "OK",
3
+ "results": [ {
4
+ "types": [ "street_address" ],
5
+ "formatted_address": "R. Tenerife, 31 - Vila Anchieta, São José do Rio Preto - São Paulo, 15050-120, Brasil",
6
+ "address_components": [ {
7
+ "long_name": "31",
8
+ "short_name": "31",
9
+ "types": [ "street_number" ]
10
+ }, {
11
+ "long_name": "R. Tenerife",
12
+ "short_name": "R. Tenerife",
13
+ "types": [ "route" ]
14
+ }, {
15
+ "long_name": "Vila Anchieta",
16
+ "short_name": "Vila Anchieta",
17
+ "types": [ "neighborhood", "political" ]
18
+ }, {
19
+ "long_name": "São José do Rio Preto",
20
+ "short_name": "São José do Rio Preto",
21
+ "types": [ "locality", "political" ]
22
+ }, {
23
+ "long_name": "São Paulo",
24
+ "short_name": "São Paulo",
25
+ "types": [ "administrative_area_level_1", "political" ]
26
+ }, {
27
+ "long_name": "Brasil",
28
+ "short_name": "BR",
29
+ "types": [ "country", "political" ]
30
+ }, {
31
+ "long_name": "15050-120",
32
+ "short_name": "15050-120",
33
+ "types": [ "postal_code" ]
34
+ } ],
35
+ "geometry": {
36
+ "location": {
37
+ "lat": -20.8011840,
38
+ "lng": -49.3747043
39
+ },
40
+ "location_type": "RANGE_INTERPOLATED",
41
+ "viewport": {
42
+ "southwest": {
43
+ "lat": -20.8043407,
44
+ "lng": -49.3778522
45
+ },
46
+ "northeast": {
47
+ "lat": -20.7980455,
48
+ "lng": -49.3715569
49
+ }
50
+ },
51
+ "bounds": {
52
+ "southwest": {
53
+ "lat": -20.8012022,
54
+ "lng": -49.3747048
55
+ },
56
+ "northeast": {
57
+ "lat": -20.8011840,
58
+ "lng": -49.3747043
59
+ }
60
+ }
61
+ }
62
+ }, {
63
+ "types": [ "street_address" ],
64
+ "formatted_address": "R. Tenerife, 31 - Jardim Atlântico, Belo Horizonte - MG, 31550-220, Brasil",
65
+ "address_components": [ {
66
+ "long_name": "31",
67
+ "short_name": "31",
68
+ "types": [ "street_number" ]
69
+ }, {
70
+ "long_name": "R. Tenerife",
71
+ "short_name": "R. Tenerife",
72
+ "types": [ "route" ]
73
+ }, {
74
+ "long_name": "Jardim Atlântico",
75
+ "short_name": "Jardim Atlântico",
76
+ "types": [ "neighborhood", "political" ]
77
+ }, {
78
+ "long_name": "Belo Horizonte",
79
+ "short_name": "Belo Horizonte",
80
+ "types": [ "locality", "political" ]
81
+ }, {
82
+ "long_name": "Minas Gerais",
83
+ "short_name": "MG",
84
+ "types": [ "administrative_area_level_1", "political" ]
85
+ }, {
86
+ "long_name": "Brasil",
87
+ "short_name": "BR",
88
+ "types": [ "country", "political" ]
89
+ }, {
90
+ "long_name": "31550-220",
91
+ "short_name": "31550-220",
92
+ "types": [ "postal_code" ]
93
+ } ],
94
+ "geometry": {
95
+ "location": {
96
+ "lat": -19.8425571,
97
+ "lng": -43.9901379
98
+ },
99
+ "location_type": "RANGE_INTERPOLATED",
100
+ "viewport": {
101
+ "southwest": {
102
+ "lat": -19.8456962,
103
+ "lng": -43.9932891
104
+ },
105
+ "northeast": {
106
+ "lat": -19.8394010,
107
+ "lng": -43.9869938
108
+ }
109
+ },
110
+ "bounds": {
111
+ "southwest": {
112
+ "lat": -19.8425571,
113
+ "lng": -43.9901450
114
+ },
115
+ "northeast": {
116
+ "lat": -19.8425401,
117
+ "lng": -43.9901379
118
+ }
119
+ }
120
+ }
121
+ }, {
122
+ "types": [ "street_address" ],
123
+ "formatted_address": "R. Tenerife, 31 - Jardim Industrial, Contagem - MG, 32220-080, Brasil",
124
+ "address_components": [ {
125
+ "long_name": "31",
126
+ "short_name": "31",
127
+ "types": [ "street_number" ]
128
+ }, {
129
+ "long_name": "R. Tenerife",
130
+ "short_name": "R. Tenerife",
131
+ "types": [ "route" ]
132
+ }, {
133
+ "long_name": "Jardim Industrial",
134
+ "short_name": "Jardim Industrial",
135
+ "types": [ "neighborhood", "political" ]
136
+ }, {
137
+ "long_name": "Contagem",
138
+ "short_name": "Contagem",
139
+ "types": [ "locality", "political" ]
140
+ }, {
141
+ "long_name": "Minas Gerais",
142
+ "short_name": "MG",
143
+ "types": [ "administrative_area_level_1", "political" ]
144
+ }, {
145
+ "long_name": "Brasil",
146
+ "short_name": "BR",
147
+ "types": [ "country", "political" ]
148
+ }, {
149
+ "long_name": "32220-080",
150
+ "short_name": "32220-080",
151
+ "types": [ "postal_code" ]
152
+ } ],
153
+ "geometry": {
154
+ "location": {
155
+ "lat": -19.9674684,
156
+ "lng": -44.0224518
157
+ },
158
+ "location_type": "RANGE_INTERPOLATED",
159
+ "viewport": {
160
+ "southwest": {
161
+ "lat": -19.9706228,
162
+ "lng": -44.0256060
163
+ },
164
+ "northeast": {
165
+ "lat": -19.9643275,
166
+ "lng": -44.0193108
167
+ }
168
+ },
169
+ "bounds": {
170
+ "southwest": {
171
+ "lat": -19.9674819,
172
+ "lng": -44.0224650
173
+ },
174
+ "northeast": {
175
+ "lat": -19.9674684,
176
+ "lng": -44.0224518
177
+ }
178
+ }
179
+ }
180
+ }, {
181
+ "types": [ "street_address" ],
182
+ "formatted_address": "R. Tenerife, 31 - Itaim Bibi, São Paulo, 04548-040, Brasil",
183
+ "address_components": [ {
184
+ "long_name": "31",
185
+ "short_name": "31",
186
+ "types": [ "street_number" ]
187
+ }, {
188
+ "long_name": "R. Tenerife",
189
+ "short_name": "R. Tenerife",
190
+ "types": [ "route" ]
191
+ }, {
192
+ "long_name": "Itaim Bibi",
193
+ "short_name": "Itaim Bibi",
194
+ "types": [ "neighborhood", "political" ]
195
+ }, {
196
+ "long_name": "São Paulo",
197
+ "short_name": "São Paulo",
198
+ "types": [ "locality", "political" ]
199
+ }, {
200
+ "long_name": "São Paulo",
201
+ "short_name": "São Paulo",
202
+ "types": [ "administrative_area_level_1", "political" ]
203
+ }, {
204
+ "long_name": "Brasil",
205
+ "short_name": "BR",
206
+ "types": [ "country", "political" ]
207
+ }, {
208
+ "long_name": "04548-040",
209
+ "short_name": "04548-040",
210
+ "types": [ "postal_code" ]
211
+ } ],
212
+ "geometry": {
213
+ "location": {
214
+ "lat": -23.5962501,
215
+ "lng": -46.6878790
216
+ },
217
+ "location_type": "RANGE_INTERPOLATED",
218
+ "viewport": {
219
+ "southwest": {
220
+ "lat": -23.5993942,
221
+ "lng": -46.6910355
222
+ },
223
+ "northeast": {
224
+ "lat": -23.5930989,
225
+ "lng": -46.6847403
226
+ }
227
+ },
228
+ "bounds": {
229
+ "southwest": {
230
+ "lat": -23.5962501,
231
+ "lng": -46.6878968
232
+ },
233
+ "northeast": {
234
+ "lat": -23.5962430,
235
+ "lng": -46.6878790
236
+ }
237
+ }
238
+ }
239
+ }, {
240
+ "types": [ "street_address" ],
241
+ "formatted_address": "R. Tenerife, 31 - Fazenda Rio Grande - PR, 83820-000, Brasil",
242
+ "address_components": [ {
243
+ "long_name": "31",
244
+ "short_name": "31",
245
+ "types": [ "street_number" ]
246
+ }, {
247
+ "long_name": "R. Tenerife",
248
+ "short_name": "R. Tenerife",
249
+ "types": [ "route" ]
250
+ }, {
251
+ "long_name": "Fazenda Rio Grande",
252
+ "short_name": "Fazenda Rio Grande",
253
+ "types": [ "locality", "political" ]
254
+ }, {
255
+ "long_name": "Paraná",
256
+ "short_name": "PR",
257
+ "types": [ "administrative_area_level_1", "political" ]
258
+ }, {
259
+ "long_name": "Brasil",
260
+ "short_name": "BR",
261
+ "types": [ "country", "political" ]
262
+ }, {
263
+ "long_name": "83820-000",
264
+ "short_name": "83820-000",
265
+ "types": [ "postal_code" ]
266
+ } ],
267
+ "geometry": {
268
+ "location": {
269
+ "lat": -25.6641852,
270
+ "lng": -49.3006341
271
+ },
272
+ "location_type": "RANGE_INTERPOLATED",
273
+ "viewport": {
274
+ "southwest": {
275
+ "lat": -25.6673372,
276
+ "lng": -49.3037901
277
+ },
278
+ "northeast": {
279
+ "lat": -25.6610420,
280
+ "lng": -49.2974949
281
+ }
282
+ },
283
+ "bounds": {
284
+ "southwest": {
285
+ "lat": -25.6641940,
286
+ "lng": -49.3006509
287
+ },
288
+ "northeast": {
289
+ "lat": -25.6641852,
290
+ "lng": -49.3006341
291
+ }
292
+ }
293
+ }
294
+ }, {
295
+ "types": [ "street_address" ],
296
+ "formatted_address": "R. Tenerife, 31 - Parada de Lucas, Rio de Janeiro - RJ, 21010-000, Brasil",
297
+ "address_components": [ {
298
+ "long_name": "31",
299
+ "short_name": "31",
300
+ "types": [ "street_number" ]
301
+ }, {
302
+ "long_name": "R. Tenerife",
303
+ "short_name": "R. Tenerife",
304
+ "types": [ "route" ]
305
+ }, {
306
+ "long_name": "Parada de Lucas",
307
+ "short_name": "Parada de Lucas",
308
+ "types": [ "neighborhood", "political" ]
309
+ }, {
310
+ "long_name": "Rio de Janeiro",
311
+ "short_name": "Rio de Janeiro",
312
+ "types": [ "locality", "political" ]
313
+ }, {
314
+ "long_name": "Rio de Janeiro",
315
+ "short_name": "RJ",
316
+ "types": [ "administrative_area_level_1", "political" ]
317
+ }, {
318
+ "long_name": "Brasil",
319
+ "short_name": "BR",
320
+ "types": [ "country", "political" ]
321
+ }, {
322
+ "long_name": "21010-000",
323
+ "short_name": "21010-000",
324
+ "types": [ "postal_code" ]
325
+ } ],
326
+ "geometry": {
327
+ "location": {
328
+ "lat": -22.8167748,
329
+ "lng": -43.2958111
330
+ },
331
+ "location_type": "RANGE_INTERPOLATED",
332
+ "viewport": {
333
+ "southwest": {
334
+ "lat": -22.8199308,
335
+ "lng": -43.2989551
336
+ },
337
+ "northeast": {
338
+ "lat": -22.8136355,
339
+ "lng": -43.2926599
340
+ }
341
+ },
342
+ "bounds": {
343
+ "southwest": {
344
+ "lat": -22.8167915,
345
+ "lng": -43.2958111
346
+ },
347
+ "northeast": {
348
+ "lat": -22.8167748,
349
+ "lng": -43.2958039
350
+ }
351
+ }
352
+ },
353
+ "partial_match": true
354
+ } ]
355
+ }
356
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "status": "NOT_FOUND",
3
+ "routes": [ ]
4
+ }
5
+
@@ -0,0 +1,426 @@
1
+ {
2
+ "status": "OK",
3
+ "routes": [ {
4
+ "summary": "Av. dos Bandeirantes",
5
+ "legs": [ {
6
+ "steps": [ {
7
+ "travel_mode": "DRIVING",
8
+ "start_location": {
9
+ "lat": -23.5962400,
10
+ "lng": -46.6879000
11
+ },
12
+ "end_location": {
13
+ "lat": -23.5968300,
14
+ "lng": -46.6881800
15
+ },
16
+ "polyline": {
17
+ "points": "ns_oCjv}{GtBv@",
18
+ "levels": "BB"
19
+ },
20
+ "duration": {
21
+ "value": 10,
22
+ "text": "1 min"
23
+ },
24
+ "html_instructions": "Siga na direção \u003cb\u003esudoeste\u003c/b\u003e na \u003cb\u003eR. Tenerife\u003c/b\u003e em direção à \u003cb\u003eAv. Dr. Cardoso de Melo\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e72&nbsp;m\u003c/b\u003e\u003c/span\u003e",
25
+ "distance": {
26
+ "value": 72,
27
+ "text": "72 m"
28
+ }
29
+ }, {
30
+ "travel_mode": "DRIVING",
31
+ "start_location": {
32
+ "lat": -23.5968300,
33
+ "lng": -46.6881800
34
+ },
35
+ "end_location": {
36
+ "lat": -23.5993100,
37
+ "lng": -46.6827900
38
+ },
39
+ "polyline": {
40
+ "points": "dw_oCbx}{GxBuFtJ_Y",
41
+ "levels": "B?B"
42
+ },
43
+ "duration": {
44
+ "value": 116,
45
+ "text": "2 minutos"
46
+ },
47
+ "html_instructions": "Pegue a primeira \u003cb\u003eà esquerda\u003c/b\u003e para pegar a \u003cb\u003eAv. Dr. Cardoso de Melo\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e600&nbsp;m\u003c/b\u003e\u003c/span\u003e",
48
+ "distance": {
49
+ "value": 615,
50
+ "text": "0,6 km"
51
+ }
52
+ }, {
53
+ "travel_mode": "DRIVING",
54
+ "start_location": {
55
+ "lat": -23.5993100,
56
+ "lng": -46.6827900
57
+ },
58
+ "end_location": {
59
+ "lat": -23.6002500,
60
+ "lng": -46.6827500
61
+ },
62
+ "polyline": {
63
+ "points": "tf`oClv|{GzDG",
64
+ "levels": "BB"
65
+ },
66
+ "duration": {
67
+ "value": 21,
68
+ "text": "1 min"
69
+ },
70
+ "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eR. Alvorada\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e110&nbsp;m\u003c/b\u003e\u003c/span\u003e",
71
+ "distance": {
72
+ "value": 105,
73
+ "text": "0,1 km"
74
+ }
75
+ }, {
76
+ "travel_mode": "DRIVING",
77
+ "start_location": {
78
+ "lat": -23.6002500,
79
+ "lng": -46.6827500
80
+ },
81
+ "end_location": {
82
+ "lat": -23.6014400,
83
+ "lng": -46.6828100
84
+ },
85
+ "polyline": {
86
+ "points": "pl`oCdv|{GhEMb@X",
87
+ "levels": "B?B"
88
+ },
89
+ "duration": {
90
+ "value": 27,
91
+ "text": "1 min"
92
+ },
93
+ "html_instructions": "Continue para \u003cb\u003eR. Dr. Manuel da Rocha Passos Filho\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e140&nbsp;m\u003c/b\u003e\u003c/span\u003e",
94
+ "distance": {
95
+ "value": 137,
96
+ "text": "0,1 km"
97
+ }
98
+ }, {
99
+ "travel_mode": "DRIVING",
100
+ "start_location": {
101
+ "lat": -23.6014400,
102
+ "lng": -46.6828100
103
+ },
104
+ "end_location": {
105
+ "lat": -23.6041800,
106
+ "lng": -46.6798400
107
+ },
108
+ "polyline": {
109
+ "points": "~s`oCpv|{GbGqHxCkCzAoBh@c@",
110
+ "levels": "B???B"
111
+ },
112
+ "duration": {
113
+ "value": 98,
114
+ "text": "2 minutos"
115
+ },
116
+ "html_instructions": "Vire à \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eAv. dos Bandeirantes\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e450&nbsp;m\u003c/b\u003e\u003c/span\u003e",
117
+ "distance": {
118
+ "value": 431,
119
+ "text": "0,4 km"
120
+ }
121
+ }, {
122
+ "travel_mode": "DRIVING",
123
+ "start_location": {
124
+ "lat": -23.6041800,
125
+ "lng": -46.6798400
126
+ },
127
+ "end_location": {
128
+ "lat": -23.6085300,
129
+ "lng": -46.6767400
130
+ },
131
+ "polyline": {
132
+ "points": "beaoC~c|{G|AaA`O{Ft@k@nEaG",
133
+ "levels": "B???B"
134
+ },
135
+ "duration": {
136
+ "value": 28,
137
+ "text": "1 min"
138
+ },
139
+ "html_instructions": "Curva suave à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eAv. dos Bandeirantes-pista Central\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e600&nbsp;m\u003c/b\u003e\u003c/span\u003e",
140
+ "distance": {
141
+ "value": 588,
142
+ "text": "0,6 km"
143
+ }
144
+ }, {
145
+ "travel_mode": "DRIVING",
146
+ "start_location": {
147
+ "lat": -23.6085300,
148
+ "lng": -46.6767400
149
+ },
150
+ "end_location": {
151
+ "lat": -23.6178200,
152
+ "lng": -46.6609300
153
+ },
154
+ "polyline": {
155
+ "points": "h`boCrp{{GjBwBrGoEvBgBbAwAtBeEbEuLrAyCdDoEvEeHhAyCtC_RxGkQ",
156
+ "levels": "B???@????@??B"
157
+ },
158
+ "duration": {
159
+ "value": 94,
160
+ "text": "2 minutos"
161
+ },
162
+ "html_instructions": "Continue para \u003cb\u003eAv. dos Bandeirantes\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e2,0&nbsp;km\u003c/b\u003e\u003c/span\u003e",
163
+ "distance": {
164
+ "value": 1957,
165
+ "text": "2,0 km"
166
+ }
167
+ }, {
168
+ "travel_mode": "DRIVING",
169
+ "start_location": {
170
+ "lat": -23.6178200,
171
+ "lng": -46.6609300
172
+ },
173
+ "end_location": {
174
+ "lat": -23.6179000,
175
+ "lng": -46.6619600
176
+ },
177
+ "polyline": {
178
+ "points": "jzcoCxmx{GnA]d@P^f@p@|A?ZMVQVYJ{AIa@D",
179
+ "levels": "B???@?????B"
180
+ },
181
+ "duration": {
182
+ "value": 38,
183
+ "text": "1 min"
184
+ },
185
+ "html_instructions": "Pegue a saída em direção a \u003cb\u003eVd. João Julião da Costa Aguiar\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e280&nbsp;m\u003c/b\u003e\u003c/span\u003e",
186
+ "distance": {
187
+ "value": 284,
188
+ "text": "0,3 km"
189
+ }
190
+ }, {
191
+ "travel_mode": "DRIVING",
192
+ "start_location": {
193
+ "lat": -23.6179000,
194
+ "lng": -46.6619600
195
+ },
196
+ "end_location": {
197
+ "lat": -23.6158800,
198
+ "lng": -46.6602800
199
+ },
200
+ "polyline": {
201
+ "points": "zzcoCftx{GoBcAcHkG",
202
+ "levels": "B?B"
203
+ },
204
+ "duration": {
205
+ "value": 27,
206
+ "text": "1 min"
207
+ },
208
+ "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eVd. João Julião da Costa Aguiar\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e280&nbsp;m\u003c/b\u003e\u003c/span\u003e",
209
+ "distance": {
210
+ "value": 284,
211
+ "text": "0,3 km"
212
+ }
213
+ }, {
214
+ "travel_mode": "DRIVING",
215
+ "start_location": {
216
+ "lat": -23.6158800,
217
+ "lng": -46.6602800
218
+ },
219
+ "end_location": {
220
+ "lat": -23.6078900,
221
+ "lng": -46.6526800
222
+ },
223
+ "polyline": {
224
+ "points": "fncoCvix{GsIiIwCaDaIwGoWkV",
225
+ "levels": "B???B"
226
+ },
227
+ "duration": {
228
+ "value": 91,
229
+ "text": "2 minutos"
230
+ },
231
+ "html_instructions": "Continue para \u003cb\u003eAv. Moreira Guimarães\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,2&nbsp;km\u003c/b\u003e\u003c/span\u003e",
232
+ "distance": {
233
+ "value": 1179,
234
+ "text": "1,2 km"
235
+ }
236
+ }, {
237
+ "travel_mode": "DRIVING",
238
+ "start_location": {
239
+ "lat": -23.6078900,
240
+ "lng": -46.6526800
241
+ },
242
+ "end_location": {
243
+ "lat": -23.5910200,
244
+ "lng": -46.6509300
245
+ },
246
+ "polyline": {
247
+ "points": "h|aoCfzv{GwCyBa@QeC_A_C[kWoA{p@cC_C?oDPuFjA",
248
+ "levels": "B???@?@??B"
249
+ },
250
+ "duration": {
251
+ "value": 93,
252
+ "text": "2 minutos"
253
+ },
254
+ "html_instructions": "Continue para \u003cb\u003eAv. Rubem Berta\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,9&nbsp;km\u003c/b\u003e\u003c/span\u003e",
255
+ "distance": {
256
+ "value": 1917,
257
+ "text": "1,9 km"
258
+ }
259
+ }, {
260
+ "travel_mode": "DRIVING",
261
+ "start_location": {
262
+ "lat": -23.5910200,
263
+ "lng": -46.6509300
264
+ },
265
+ "end_location": {
266
+ "lat": -23.5787000,
267
+ "lng": -46.6463300
268
+ },
269
+ "polyline": {
270
+ "points": "zr~nChov{Gq_@~MuCJgAGiAUqCqAkB}AeKiPaNkS",
271
+ "levels": "B@??@???B"
272
+ },
273
+ "duration": {
274
+ "value": 84,
275
+ "text": "1 min"
276
+ },
277
+ "html_instructions": "Continue para \u003cb\u003eAv. Vinte e Três de Maio\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,7&nbsp;km\u003c/b\u003e\u003c/span\u003e",
278
+ "distance": {
279
+ "value": 1747,
280
+ "text": "1,7 km"
281
+ }
282
+ }, {
283
+ "travel_mode": "DRIVING",
284
+ "start_location": {
285
+ "lat": -23.5787000,
286
+ "lng": -46.6463300
287
+ },
288
+ "end_location": {
289
+ "lat": -23.5785200,
290
+ "lng": -46.6457800
291
+ },
292
+ "polyline": {
293
+ "points": "ze|nCpru{Gc@mB",
294
+ "levels": "BB"
295
+ },
296
+ "duration": {
297
+ "value": 15,
298
+ "text": "1 min"
299
+ },
300
+ "html_instructions": "Curva suave à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003ePraça Toronto\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e60&nbsp;m\u003c/b\u003e\u003c/span\u003e",
301
+ "distance": {
302
+ "value": 60,
303
+ "text": "60 m"
304
+ }
305
+ }, {
306
+ "travel_mode": "DRIVING",
307
+ "start_location": {
308
+ "lat": -23.5785200,
309
+ "lng": -46.6457800
310
+ },
311
+ "end_location": {
312
+ "lat": -23.5771500,
313
+ "lng": -46.6407500
314
+ },
315
+ "polyline": {
316
+ "points": "vd|nCbou{Gk@gDkCcLyAaL",
317
+ "levels": "B??B"
318
+ },
319
+ "duration": {
320
+ "value": 93,
321
+ "text": "2 minutos"
322
+ },
323
+ "html_instructions": "Continue para \u003cb\u003eR. Estela\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e550&nbsp;m\u003c/b\u003e\u003c/span\u003e",
324
+ "distance": {
325
+ "value": 536,
326
+ "text": "0,5 km"
327
+ }
328
+ }, {
329
+ "travel_mode": "DRIVING",
330
+ "start_location": {
331
+ "lat": -23.5771500,
332
+ "lng": -46.6407500
333
+ },
334
+ "end_location": {
335
+ "lat": -23.5763400,
336
+ "lng": -46.6409600
337
+ },
338
+ "polyline": {
339
+ "points": "d|{nCtot{G}APcAV",
340
+ "levels": "B?B"
341
+ },
342
+ "duration": {
343
+ "value": 39,
344
+ "text": "1 min"
345
+ },
346
+ "html_instructions": "Vire à \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eR. Vergueiro\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e93&nbsp;m\u003c/b\u003e\u003c/span\u003e",
347
+ "distance": {
348
+ "value": 93,
349
+ "text": "93 m"
350
+ }
351
+ }, {
352
+ "travel_mode": "DRIVING",
353
+ "start_location": {
354
+ "lat": -23.5763400,
355
+ "lng": -46.6409600
356
+ },
357
+ "end_location": {
358
+ "lat": -23.5712300,
359
+ "lng": -46.6441400
360
+ },
361
+ "polyline": {
362
+ "points": "bw{nC~pt{GqF|BaAPuOhGsD`F",
363
+ "levels": "B??@B"
364
+ },
365
+ "duration": {
366
+ "value": 88,
367
+ "text": "1 min"
368
+ },
369
+ "html_instructions": "Continue para \u003cb\u003eAv. Bernardino de Campos/Vd. Santa Generosa\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e650&nbsp;m\u003c/b\u003e\u003c/span\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinue na Av. Bernardino de Campos\u003c/div\u003e",
370
+ "distance": {
371
+ "value": 666,
372
+ "text": "0,7 km"
373
+ }
374
+ }, {
375
+ "travel_mode": "DRIVING",
376
+ "start_location": {
377
+ "lat": -23.5712300,
378
+ "lng": -46.6441400
379
+ },
380
+ "end_location": {
381
+ "lat": -23.5706500,
382
+ "lng": -46.6449200
383
+ },
384
+ "polyline": {
385
+ "points": "dwznCzdu{GsBzC",
386
+ "levels": "BB"
387
+ },
388
+ "duration": {
389
+ "value": 30,
390
+ "text": "1 min"
391
+ },
392
+ "html_instructions": "Continue para \u003cb\u003eAv. Paulista\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e100&nbsp;m\u003c/b\u003e\u003c/span\u003e\u003cdiv style=\"font-size:0.9em\"\u003eO destino estará à direita\u003c/div\u003e",
393
+ "distance": {
394
+ "value": 103,
395
+ "text": "0,1 km"
396
+ }
397
+ } ],
398
+ "duration": {
399
+ "value": 992,
400
+ "text": "17 minutos"
401
+ },
402
+ "distance": {
403
+ "value": 10774,
404
+ "text": "10,8 km"
405
+ },
406
+ "start_location": {
407
+ "lat": -23.5962400,
408
+ "lng": -46.6879000
409
+ },
410
+ "end_location": {
411
+ "lat": -23.5706500,
412
+ "lng": -46.6449200
413
+ },
414
+ "start_address": "R. Tenerife, 31 - Itaim Bibi, São Paulo, 04548-040, Brasil",
415
+ "end_address": "Av. Paulista, 100 - Bela Vista, São Paulo, 01310-000, Brasil"
416
+ } ],
417
+ "copyrights": "Map data ©2010 MapLink",
418
+ "overview_polyline": {
419
+ "points": "ns_oCjv}{GtBv@xBuFtJ_YdKUb@XbGqHxCkCzAoBbA{@bAi@`O{Ft@k@|EwG|AaBrGoEvBgB~BsDx@iBbEuLrAyCfH{JzB}Db@uAh@sCfAoIb@{BxGkQnA]l@Xl@bAZx@?Z_@n@YJ{AIa@DoBcAcHkGsIiIwCaDaIwGwHaHgNyMgCiB{B_AcBa@sY{AeYgAuV{@kFFkAJmFhAq_@~MuCJgAGiAUqCqAkB}AeKiPaNkSoAuGkCcLyAaL}APcAVqF|BaAPuOhGgH|J",
420
+ "levels": "B@?@?@???@?@????@?????@????@??A???@??@????????@???@??@??@???@??@????@B"
421
+ },
422
+ "warnings": [ ],
423
+ "waypoint_order": [ ]
424
+ } ]
425
+ }
426
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GoMaps::Address do
4
+ context 'on #exists?' do
5
+ it 'should return true given a valid address' do
6
+ address = 'Valid Address'
7
+ map_address_to_file address, 'address_success'
8
+ GoMaps::Address.new(address).exists?.should be_true
9
+ end
10
+
11
+ it 'should return false given an invalid address' do
12
+ address = 'Invalid Address'
13
+ map_address_to_file address, 'address_error'
14
+ GoMaps::Address.new(address).exists?.should be_false
15
+ end
16
+ end
17
+
18
+ context 'on #distance_to' do
19
+ it 'should return the distance given valid addresses' do
20
+ address1, address2 = 'Valid Address 1', 'Valid Address 2'
21
+ map_addresses_to_file address1, address2, 'distance_success_10.8'
22
+ GoMaps::Address.new(address1).distance_to(address2).should == 10.8
23
+ end
24
+
25
+ it 'should raise AddressNotFoundException given invalid addresses' do
26
+ address1, address2 = 'Invalid Address 1', 'Invalid Address 2'
27
+ map_addresses_to_file address1, address2, 'distance_error'
28
+ lambda { GoMaps::Address.new(address1).distance_to(address2) }.should raise_error(GoMaps::AddressNotFoundException)
29
+ end
30
+ end
31
+ end
32
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'go_maps'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'fakeweb'
8
+
9
+ Spec::Runner.configure do |config|
10
+ FakeWeb.allow_net_connect = false
11
+ end
12
+
13
+ def map_addresses_to_file(address1, address2, file_name)
14
+ map_query_string_to_file "origin=#{address1}&destination=#{address2}", file_name
15
+ end
16
+
17
+ def map_address_to_file(address, file_name)
18
+ map_query_string_to_file "address=#{address}", file_name
19
+ end
20
+
21
+ def map_query_string_to_file(query_string, file_name)
22
+ api = query_string.include?('destination') ? 'directions' : 'geocode'
23
+ map_url_to_file "http://maps.google.com/maps/api/#{api}/json?sensor=false&language=pt-BR&#{query_string}", file_name
24
+ end
25
+
26
+ def map_url_to_file(url, file_name)
27
+ FakeWeb.register_uri(:get, URI.escape(url), :body => File.open("#{File.dirname(__FILE__)}/data/#{file_name}").read)
28
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_maps
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Gonow
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-09 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: fakeweb
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 8
45
+ version: 1.2.8
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: crack
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 1
58
+ - 6
59
+ version: 0.1.6
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Ruby API to geographic operations
63
+ email:
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - README.markdown
70
+ files:
71
+ - .gitignore
72
+ - README.markdown
73
+ - Rakefile
74
+ - lib/go_maps.rb
75
+ - lib/go_maps/address.rb
76
+ - lib/go_maps/address_not_found_exception.rb
77
+ - spec/data/address_error
78
+ - spec/data/address_success
79
+ - spec/data/distance_error
80
+ - spec/data/distance_success_10.8
81
+ - spec/go_maps/address_spec.rb
82
+ - spec/spec.opts
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/gonow/go_maps
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Ruby API to geographic operations
114
+ test_files:
115
+ - spec/go_maps/address_spec.rb
116
+ - spec/spec_helper.rb