go_maps 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,13 +1,34 @@
1
1
  ## ABOUT
2
2
 
3
- Ruby API to geographic operations. Currently it supports the validation of an address and the distance between two of them.
3
+ Ruby API to geographic operations. Currently it supports:
4
+
5
+ * Validation of an address
6
+ * Distance between two addresses
7
+ * Map with route between two addresses
8
+ * Directions in HTML format between two addresses
9
+ * Load address data from a CEP (only for Brazil)
4
10
 
5
11
  ## USAGE
6
12
 
7
- address = Address.new "Rua Tenerife, 31, Sao Paulo, Brasil"
13
+ address = GoMaps::Address.new "Rua Tenerife, 31, Sao Paulo, Brasil"
8
14
  address.exists?
15
+ => true
9
16
  address.distance_to "Av Paulista, Sao Paulo, Brasil"
10
- GoMaps::Direction.new(:from => "Av Paulista 100, Sao Paulo, Brasil", :to => "Avenida Brigadeiro Faria Lima 1000, Sao Paulo, Brasil").to_map
17
+ => 6.3
18
+
19
+ direction = GoMaps::Direction.new(:from => "Av Paulista 100, Sao Paulo, Brasil",
20
+ :to => "Avenida Brigadeiro Faria Lima 1000, Sao Paulo, Brasil")
21
+ direction.to_map
22
+ direction.to_map(:width => 400, :height => 700)
23
+ direction.to_html
24
+ direction.to_html(:language => 'pt-BR')
25
+
26
+ cep = GoMaps::CEP.new('01310-000')
27
+ cep.street
28
+ => "Avenida Paulista"
29
+ cep.city
30
+ => "São Paulo"
31
+
11
32
 
12
33
  ## LICENSE
13
34
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  require 'jeweler'
8
8
  Jeweler::Tasks.new do |gem|
9
9
  gem.name = "go_maps"
10
- gem.version = "0.2.0"
10
+ gem.version = "0.3.0"
11
11
  gem.summary = %Q{Ruby API to geographic operations}
12
12
  gem.description = %Q{Ruby API to geographic operations}
13
13
  gem.homepage = "http://github.com/gonow/go_maps"
@@ -15,6 +15,7 @@ begin
15
15
  gem.add_development_dependency "rspec", ">= 1.2.9"
16
16
  gem.add_development_dependency "fakeweb", ">= 1.2.8"
17
17
  gem.add_dependency("crack", ">= 0.1.6")
18
+ gem.add_dependency("nokogiri", ">= 1.4.1")
18
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
20
  end
20
21
  Jeweler::GemcutterTasks.new
data/go_maps.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{go_maps}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gonow"]
12
- s.date = %q{2010-07-13}
12
+ s.date = %q{2010-07-16}
13
13
  s.description = %q{Ruby API to geographic operations}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -22,12 +22,19 @@ Gem::Specification.new do |s|
22
22
  "lib/go_maps.rb",
23
23
  "lib/go_maps/address.rb",
24
24
  "lib/go_maps/address_not_found_exception.rb",
25
+ "lib/go_maps/cep.rb",
25
26
  "lib/go_maps/direction.rb",
26
27
  "spec/data/address_error",
27
28
  "spec/data/address_success",
29
+ "spec/data/cep_error",
30
+ "spec/data/cep_success",
31
+ "spec/data/direction_error",
32
+ "spec/data/direction_success",
33
+ "spec/data/direction_success_pt-BR",
28
34
  "spec/data/distance_error",
29
35
  "spec/data/distance_success_10.8",
30
36
  "spec/go_maps/address_spec.rb",
37
+ "spec/go_maps/cep_spec.rb",
31
38
  "spec/go_maps/direction_spec.rb",
32
39
  "spec/spec.opts",
33
40
  "spec/spec_helper.rb"
@@ -39,6 +46,7 @@ Gem::Specification.new do |s|
39
46
  s.summary = %q{Ruby API to geographic operations}
40
47
  s.test_files = [
41
48
  "spec/go_maps/address_spec.rb",
49
+ "spec/go_maps/cep_spec.rb",
42
50
  "spec/go_maps/direction_spec.rb",
43
51
  "spec/spec_helper.rb"
44
52
  ]
@@ -51,15 +59,18 @@ Gem::Specification.new do |s|
51
59
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
52
60
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
53
61
  s.add_runtime_dependency(%q<crack>, [">= 0.1.6"])
62
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
54
63
  else
55
64
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
65
  s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
57
66
  s.add_dependency(%q<crack>, [">= 0.1.6"])
67
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
58
68
  end
59
69
  else
60
70
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
71
  s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
62
72
  s.add_dependency(%q<crack>, [">= 0.1.6"])
73
+ s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
63
74
  end
64
75
  end
65
76
 
@@ -9,13 +9,18 @@ module GoMaps
9
9
  end
10
10
 
11
11
  def distance_to(address)
12
- directions_to(address)['routes'].first['legs'].first['distance']['text'].to_f rescue raise AddressNotFoundException
12
+ route_to(address)['distance']['text'].to_f
13
+ end
14
+
15
+ def route_to(address, options = {})
16
+ options[:language] ||= 'en'
17
+ directions_to(address, "&language=#{options[:language]}")['routes'].first['legs'].first rescue raise AddressNotFoundException
13
18
  end
14
19
 
15
20
  private
16
21
 
17
- def directions_to(address)
18
- api_response :directions, "origin=#{@address}&destination=#{address}"
22
+ def directions_to(address, language)
23
+ api_response :directions, "origin=#{@address}&destination=#{address}#{language}"
19
24
  end
20
25
 
21
26
  def location
@@ -0,0 +1,22 @@
1
+ module GoMaps
2
+ class CEP
3
+ def initialize(cep)
4
+ @response = Nokogiri::XML(open("http://www.buscarcep.com.br?formato=xml&cep=#{cep}"))
5
+ raise GoMaps::AddressNotFoundException if element('resultado') != '1'
6
+ end
7
+
8
+ def street
9
+ "#{element('tipo_logradouro')} #{element('logradouro')}"
10
+ end
11
+
12
+ def city
13
+ element('cidade')
14
+ end
15
+
16
+ private
17
+
18
+ def element(name)
19
+ @response.css(name).inner_text
20
+ end
21
+ end
22
+ end
@@ -6,9 +6,13 @@ module GoMaps
6
6
  end
7
7
 
8
8
  def to_map(options = {})
9
- width = options[:width] || 425
10
- height = options[:height] || 350
11
- "<iframe width='#{width}' height='#{height}' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='#{map_url(@from, @to)}'></iframe>"
9
+ options[:width] ||= 425
10
+ options[:height] ||= 350
11
+ "<iframe width='#{options[:width]}' height='#{options[:height]}' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='#{map_url(@from, @to)}'></iframe>"
12
+ end
13
+
14
+ def to_html(options = {})
15
+ Address.new(@from).route_to(@to, :language => options[:language])['steps'].inject(''){|directions, step| directions << step['html_instructions']}
12
16
  end
13
17
 
14
18
  private
data/lib/go_maps.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'crack'
2
2
  require 'open-uri'
3
+ require 'nokogiri'
3
4
 
4
5
  Dir.glob(File.dirname(__FILE__) + '/go_maps/*.rb').each { |file| require file }
5
6
 
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?><webservicecep><quantidade>1</quantidade><retorno><resultado>-1</resultado><local_busca>loc</local_busca><resultado_txt>cep nao encontrado</resultado_txt><cep>12345678</cep><codigo_ibge>codigo ibge nao encontrado</codigo_ibge></retorno></webservicecep>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?><webservicecep><quantidade>1</quantidade><retorno><cep>01310000</cep><uf>SP</uf><cidade>S�o Paulo</cidade><bairro>Bela Vista</bairro><tipo_logradouro>Avenida</tipo_logradouro><logradouro>Paulista</logradouro><complemento>- at� 0610 - lado par</complemento><data>2010-06-02 08:05:23</data><resultado>1</resultado><resultado_txt>sucesso. cep encontrado local</resultado_txt><limite_buscas>5</limite_buscas><ibge_uf>35</ibge_uf><ibge_municipio>355030</ibge_municipio><ibge_municipio_verificador>3550308</ibge_municipio_verificador></retorno></webservicecep>
@@ -0,0 +1,5 @@
1
+ {
2
+ "status": "ZERO_RESULTS",
3
+ "results": [ ]
4
+ }
5
+
@@ -0,0 +1,356 @@
1
+ {
2
+ "status": "OK",
3
+ "routes": [ {
4
+ "summary": "R. da Consolação",
5
+ "legs": [ {
6
+ "steps": [ {
7
+ "travel_mode": "DRIVING",
8
+ "start_location": {
9
+ "lat": -23.5489400,
10
+ "lng": -46.6388200
11
+ },
12
+ "end_location": {
13
+ "lat": -23.5471000,
14
+ "lng": -46.6378600
15
+ },
16
+ "polyline": {
17
+ "points": "zkvnCrct{Ga@BcAMqCyAwB{A",
18
+ "levels": "B???B"
19
+ },
20
+ "duration": {
21
+ "value": 21,
22
+ "text": "1 min"
23
+ },
24
+ "html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eAv. Vinte e Três de Maio\u003c/b\u003e",
25
+ "distance": {
26
+ "value": 233,
27
+ "text": "0.2 km"
28
+ }
29
+ }, {
30
+ "travel_mode": "DRIVING",
31
+ "start_location": {
32
+ "lat": -23.5471000,
33
+ "lng": -46.6378600
34
+ },
35
+ "end_location": {
36
+ "lat": -23.5435300,
37
+ "lng": -46.6354900
38
+ },
39
+ "polyline": {
40
+ "points": "j`vnCr}s{G_A{@_LaIiF{A",
41
+ "levels": "B??B"
42
+ },
43
+ "duration": {
44
+ "value": 42,
45
+ "text": "1 min"
46
+ },
47
+ "html_instructions": "Continue onto \u003cb\u003eAv. Nove de Julho\u003c/b\u003e",
48
+ "distance": {
49
+ "value": 469,
50
+ "text": "0.5 km"
51
+ }
52
+ }, {
53
+ "travel_mode": "DRIVING",
54
+ "start_location": {
55
+ "lat": -23.5435300,
56
+ "lng": -46.6354900
57
+ },
58
+ "end_location": {
59
+ "lat": -23.5413800,
60
+ "lng": -46.6341800
61
+ },
62
+ "polyline": {
63
+ "points": "`junCxns{GoBmA}HwD",
64
+ "levels": "B?B"
65
+ },
66
+ "duration": {
67
+ "value": 25,
68
+ "text": "1 min"
69
+ },
70
+ "html_instructions": "Continue onto \u003cb\u003eAv. Prestes Maia\u003c/b\u003e",
71
+ "distance": {
72
+ "value": 274,
73
+ "text": "0.3 km"
74
+ }
75
+ }, {
76
+ "travel_mode": "DRIVING",
77
+ "start_location": {
78
+ "lat": -23.5413800,
79
+ "lng": -46.6341800
80
+ },
81
+ "end_location": {
82
+ "lat": -23.5396300,
83
+ "lng": -46.6337300
84
+ },
85
+ "polyline": {
86
+ "points": "r|tnCrfs{G}@q@_Hg@",
87
+ "levels": "B?B"
88
+ },
89
+ "duration": {
90
+ "value": 50,
91
+ "text": "1 min"
92
+ },
93
+ "html_instructions": "Slight \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eR. Carlos de Sousa Nazaré\u003c/b\u003e",
94
+ "distance": {
95
+ "value": 204,
96
+ "text": "0.2 km"
97
+ }
98
+ }, {
99
+ "travel_mode": "DRIVING",
100
+ "start_location": {
101
+ "lat": -23.5396300,
102
+ "lng": -46.6337300
103
+ },
104
+ "end_location": {
105
+ "lat": -23.5393200,
106
+ "lng": -46.6337000
107
+ },
108
+ "polyline": {
109
+ "points": "tqtnCxcs{G}@E",
110
+ "levels": "BB"
111
+ },
112
+ "duration": {
113
+ "value": 5,
114
+ "text": "1 min"
115
+ },
116
+ "html_instructions": "Take the ramp to \u003cb\u003eAv. Sen. Queirós\u003c/b\u003e",
117
+ "distance": {
118
+ "value": 35,
119
+ "text": "35 m"
120
+ }
121
+ }, {
122
+ "travel_mode": "DRIVING",
123
+ "start_location": {
124
+ "lat": -23.5393200,
125
+ "lng": -46.6337000
126
+ },
127
+ "end_location": {
128
+ "lat": -23.5393100,
129
+ "lng": -46.6363100
130
+ },
131
+ "polyline": {
132
+ "points": "votnCrcs{GMnCcAzGJn@bAl@",
133
+ "levels": "B???B"
134
+ },
135
+ "duration": {
136
+ "value": 101,
137
+ "text": "2 mins"
138
+ },
139
+ "html_instructions": "Turn \u003cb\u003eleft\u003c/b\u003e at \u003cb\u003eAv. Sen. Queirós\u003c/b\u003e",
140
+ "distance": {
141
+ "value": 293,
142
+ "text": "0.3 km"
143
+ }
144
+ }, {
145
+ "travel_mode": "DRIVING",
146
+ "start_location": {
147
+ "lat": -23.5393100,
148
+ "lng": -46.6363100
149
+ },
150
+ "end_location": {
151
+ "lat": -23.5395400,
152
+ "lng": -46.6363600
153
+ },
154
+ "polyline": {
155
+ "points": "totnC|ss{Gl@H",
156
+ "levels": "BB"
157
+ },
158
+ "duration": {
159
+ "value": 5,
160
+ "text": "1 min"
161
+ },
162
+ "html_instructions": "Slight \u003cb\u003eleft\u003c/b\u003e at \u003cb\u003eAv. Cásper Líbero\u003c/b\u003e",
163
+ "distance": {
164
+ "value": 26,
165
+ "text": "26 m"
166
+ }
167
+ }, {
168
+ "travel_mode": "DRIVING",
169
+ "start_location": {
170
+ "lat": -23.5395400,
171
+ "lng": -46.6363600
172
+ },
173
+ "end_location": {
174
+ "lat": -23.5472000,
175
+ "lng": -46.6457900
176
+ },
177
+ "polyline": {
178
+ "points": "bqtnCfts{GpK`RhG|GFVlCdDvBnDrBhBhC|CdCvDlEnD",
179
+ "levels": "B????????B"
180
+ },
181
+ "duration": {
182
+ "value": 168,
183
+ "text": "3 mins"
184
+ },
185
+ "html_instructions": "Slight \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eAv. Ipiranga\u003c/b\u003e",
186
+ "distance": {
187
+ "value": 1292,
188
+ "text": "1.3 km"
189
+ }
190
+ }, {
191
+ "travel_mode": "DRIVING",
192
+ "start_location": {
193
+ "lat": -23.5472000,
194
+ "lng": -46.6457900
195
+ },
196
+ "end_location": {
197
+ "lat": -23.5562100,
198
+ "lng": -46.6641000
199
+ },
200
+ "polyline": {
201
+ "points": "~`vnCdou{GMjD^pDzHh]bGnM~KfWfItM~H~JvBvDV~@",
202
+ "levels": "B??@?????B"
203
+ },
204
+ "duration": {
205
+ "value": 227,
206
+ "text": "4 mins"
207
+ },
208
+ "html_instructions": "Turn \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eR. da Consolação\u003c/b\u003e",
209
+ "distance": {
210
+ "value": 2157,
211
+ "text": "2.2 km"
212
+ }
213
+ }, {
214
+ "travel_mode": "DRIVING",
215
+ "start_location": {
216
+ "lat": -23.5562100,
217
+ "lng": -46.6641000
218
+ },
219
+ "end_location": {
220
+ "lat": -23.5640900,
221
+ "lng": -46.6778000
222
+ },
223
+ "polyline": {
224
+ "points": "hywnCray{Gn@hErArF`IjMjJxS|F|KzBxDfCnD`CbEpBbE",
225
+ "levels": "B?@??????B"
226
+ },
227
+ "duration": {
228
+ "value": 150,
229
+ "text": "3 mins"
230
+ },
231
+ "html_instructions": "Continue onto \u003cb\u003eAv. Rebouças\u003c/b\u003e",
232
+ "distance": {
233
+ "value": 1660,
234
+ "text": "1.7 km"
235
+ }
236
+ }, {
237
+ "travel_mode": "DRIVING",
238
+ "start_location": {
239
+ "lat": -23.5640900,
240
+ "lng": -46.6778000
241
+ },
242
+ "end_location": {
243
+ "lat": -23.5614200,
244
+ "lng": -46.6797600
245
+ },
246
+ "polyline": {
247
+ "points": "pjynCfw{{GuOfK",
248
+ "levels": "BB"
249
+ },
250
+ "duration": {
251
+ "value": 48,
252
+ "text": "1 min"
253
+ },
254
+ "html_instructions": "Turn \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eR. Henrique Schaumann\u003c/b\u003e",
255
+ "distance": {
256
+ "value": 358,
257
+ "text": "0.4 km"
258
+ }
259
+ }, {
260
+ "travel_mode": "DRIVING",
261
+ "start_location": {
262
+ "lat": -23.5614200,
263
+ "lng": -46.6797600
264
+ },
265
+ "end_location": {
266
+ "lat": -23.5625200,
267
+ "lng": -46.6816000
268
+ },
269
+ "polyline": {
270
+ "points": "zyxnCnc|{GzEnJ",
271
+ "levels": "BB"
272
+ },
273
+ "duration": {
274
+ "value": 64,
275
+ "text": "1 min"
276
+ },
277
+ "html_instructions": "Take the 1st \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eR. Artur de Azevedo\u003c/b\u003e",
278
+ "distance": {
279
+ "value": 224,
280
+ "text": "0.2 km"
281
+ }
282
+ }, {
283
+ "travel_mode": "DRIVING",
284
+ "start_location": {
285
+ "lat": -23.5625200,
286
+ "lng": -46.6816000
287
+ },
288
+ "end_location": {
289
+ "lat": -23.5644800,
290
+ "lng": -46.6801000
291
+ },
292
+ "polyline": {
293
+ "points": "v`ynC~n|{GfKkH",
294
+ "levels": "BB"
295
+ },
296
+ "duration": {
297
+ "value": 46,
298
+ "text": "1 min"
299
+ },
300
+ "html_instructions": "Turn \u003cb\u003eleft\u003c/b\u003e at \u003cb\u003eR. Con. Eugênio Leite\u003c/b\u003e",
301
+ "distance": {
302
+ "value": 266,
303
+ "text": "0.3 km"
304
+ }
305
+ }, {
306
+ "travel_mode": "DRIVING",
307
+ "start_location": {
308
+ "lat": -23.5644800,
309
+ "lng": -46.6801000
310
+ },
311
+ "end_location": {
312
+ "lat": -23.5642400,
313
+ "lng": -46.6792200
314
+ },
315
+ "polyline": {
316
+ "points": "~lynCre|{Go@gC?g@",
317
+ "levels": "B?B"
318
+ },
319
+ "duration": {
320
+ "value": 21,
321
+ "text": "1 min"
322
+ },
323
+ "html_instructions": "Take the 1st \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eR. dos Pinheiros\u003c/b\u003e \u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the left\u003c/div\u003e",
324
+ "distance": {
325
+ "value": 95,
326
+ "text": "0.1 km"
327
+ }
328
+ } ],
329
+ "duration": {
330
+ "value": 973,
331
+ "text": "16 mins"
332
+ },
333
+ "distance": {
334
+ "value": 7586,
335
+ "text": "7.6 km"
336
+ },
337
+ "start_location": {
338
+ "lat": -23.5489400,
339
+ "lng": -46.6388200
340
+ },
341
+ "end_location": {
342
+ "lat": -23.5642400,
343
+ "lng": -46.6792200
344
+ },
345
+ "start_address": "São Paulo, Brazil",
346
+ "end_address": "R. dos Pinheiros, 100 - Pinheiros, São Paulo, 05422-000, Brazil"
347
+ } ],
348
+ "copyrights": "Map data ©2010 MapLink",
349
+ "overview_polyline": {
350
+ "points": "zkvnCrct{Ga@BcAMwAs@kBiAeCsB_LaIiF{AoBmA}HwD}@q@}Im@MnCcAzGJn@bAl@l@HPP~JnQhG|GFVlCdDvBnDrBhBhC|CdCvDlEnDMjD^pDzHh]bGnM~KfWfItM~H~JvBvDf@jB^|CrArF`IjMjJxS|F|KzBxDfCnD`CbEpBbEuOfKzEnJfKkHo@gC?g@",
351
+ "levels": "B?????????@A??@???????????@??@??????????????@@@@?B"
352
+ },
353
+ "warnings": [ ],
354
+ "waypoint_order": [ ]
355
+ } ]
356
+ }
@@ -0,0 +1,241 @@
1
+ {
2
+ "status": "OK",
3
+ "routes": [ {
4
+ "summary": "Av. Brg. Faria Lima",
5
+ "legs": [ {
6
+ "steps": [ {
7
+ "travel_mode": "DRIVING",
8
+ "start_location": {
9
+ "lat": -23.5642400,
10
+ "lng": -46.6792200
11
+ },
12
+ "end_location": {
13
+ "lat": -23.5644200,
14
+ "lng": -46.6784300
15
+ },
16
+ "polyline": {
17
+ "points": "nkynCb`|{G@qA`@kA",
18
+ "levels": "B?B"
19
+ },
20
+ "duration": {
21
+ "value": 13,
22
+ "text": "1 min"
23
+ },
24
+ "html_instructions": "Siga na direção \u003cb\u003eleste\u003c/b\u003e na \u003cb\u003eR. dos Pinheiros\u003c/b\u003e em direção à \u003cb\u003eR. Francisco Leitão\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e85&nbsp;m\u003c/b\u003e\u003c/span\u003e",
25
+ "distance": {
26
+ "value": 85,
27
+ "text": "85 m"
28
+ }
29
+ }, {
30
+ "travel_mode": "DRIVING",
31
+ "start_location": {
32
+ "lat": -23.5644200,
33
+ "lng": -46.6784300
34
+ },
35
+ "end_location": {
36
+ "lat": -23.5693200,
37
+ "lng": -46.6876400
38
+ },
39
+ "polyline": {
40
+ "points": "rlynCd{{{Gr]px@",
41
+ "levels": "BB"
42
+ },
43
+ "duration": {
44
+ "value": 142,
45
+ "text": "2 minutos"
46
+ },
47
+ "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eAv. Rebouças\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,1&nbsp;km\u003c/b\u003e\u003c/span\u003e",
48
+ "distance": {
49
+ "value": 1085,
50
+ "text": "1,1 km"
51
+ }
52
+ }, {
53
+ "travel_mode": "DRIVING",
54
+ "start_location": {
55
+ "lat": -23.5693200,
56
+ "lng": -46.6876400
57
+ },
58
+ "end_location": {
59
+ "lat": -23.5706800,
60
+ "lng": -46.6904100
61
+ },
62
+ "polyline": {
63
+ "points": "fkznCvt}{GnGhP",
64
+ "levels": "BB"
65
+ },
66
+ "duration": {
67
+ "value": 71,
68
+ "text": "1 min"
69
+ },
70
+ "html_instructions": "Curva suave à \u003cb\u003edireita\u003c/b\u003e para permanecer na \u003cb\u003eAv. Rebouças\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e300&nbsp;m\u003c/b\u003e\u003c/span\u003e",
71
+ "distance": {
72
+ "value": 321,
73
+ "text": "0,3 km"
74
+ }
75
+ }, {
76
+ "travel_mode": "DRIVING",
77
+ "start_location": {
78
+ "lat": -23.5706800,
79
+ "lng": -46.6904100
80
+ },
81
+ "end_location": {
82
+ "lat": -23.5693900,
83
+ "lng": -46.6916500
84
+ },
85
+ "polyline": {
86
+ "points": "vsznC`f~{GBr@Mh@kBjAkClA",
87
+ "levels": "B???B"
88
+ },
89
+ "duration": {
90
+ "value": 18,
91
+ "text": "1 min"
92
+ },
93
+ "html_instructions": "Pegue a rampa de acesso para a \u003cb\u003eAv. Brg. Faria Lima\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e210&nbsp;m\u003c/b\u003e\u003c/span\u003e",
94
+ "distance": {
95
+ "value": 208,
96
+ "text": "0,2 km"
97
+ }
98
+ }, {
99
+ "travel_mode": "DRIVING",
100
+ "start_location": {
101
+ "lat": -23.5693900,
102
+ "lng": -46.6916500
103
+ },
104
+ "end_location": {
105
+ "lat": -23.5945400,
106
+ "lng": -46.6803600
107
+ },
108
+ "polyline": {
109
+ "points": "tkznCxm~{GAr@|p@q^nLaG`DoAvBk@xTmIpF}@zJcCdIsAxR_EvLqB",
110
+ "levels": "B?????@????B"
111
+ },
112
+ "duration": {
113
+ "value": 373,
114
+ "text": "6 minutos"
115
+ },
116
+ "html_instructions": "Faça um \u003cb\u003eretorno\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e3,1&nbsp;km\u003c/b\u003e\u003c/span\u003e",
117
+ "distance": {
118
+ "value": 3084,
119
+ "text": "3,1 km"
120
+ }
121
+ }, {
122
+ "travel_mode": "DRIVING",
123
+ "start_location": {
124
+ "lat": -23.5945400,
125
+ "lng": -46.6803600
126
+ },
127
+ "end_location": {
128
+ "lat": -23.5950500,
129
+ "lng": -46.6821700
130
+ },
131
+ "polyline": {
132
+ "points": "zh_oCfg|{GdBhJ",
133
+ "levels": "BB"
134
+ },
135
+ "duration": {
136
+ "value": 31,
137
+ "text": "1 min"
138
+ },
139
+ "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eR. Elvira Ferraz\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e190&nbsp;m\u003c/b\u003e\u003c/span\u003e",
140
+ "distance": {
141
+ "value": 192,
142
+ "text": "0,2 km"
143
+ }
144
+ }, {
145
+ "travel_mode": "DRIVING",
146
+ "start_location": {
147
+ "lat": -23.5950500,
148
+ "lng": -46.6821700
149
+ },
150
+ "end_location": {
151
+ "lat": -23.5961200,
152
+ "lng": -46.6873500
153
+ },
154
+ "polyline": {
155
+ "points": "`l_oCpr|{GXlCYfBvBfN|AlH",
156
+ "levels": "B???B"
157
+ },
158
+ "duration": {
159
+ "value": 85,
160
+ "text": "1 min"
161
+ },
162
+ "html_instructions": "Continue para \u003cb\u003eR. Olimpíadas\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e550&nbsp;m\u003c/b\u003e\u003c/span\u003e",
163
+ "distance": {
164
+ "value": 549,
165
+ "text": "0,5 km"
166
+ }
167
+ }, {
168
+ "travel_mode": "DRIVING",
169
+ "start_location": {
170
+ "lat": -23.5961200,
171
+ "lng": -46.6873500
172
+ },
173
+ "end_location": {
174
+ "lat": -23.5959300,
175
+ "lng": -46.6877500
176
+ },
177
+ "polyline": {
178
+ "points": "vr_oC|r}{Ge@nA",
179
+ "levels": "BB"
180
+ },
181
+ "duration": {
182
+ "value": 13,
183
+ "text": "1 min"
184
+ },
185
+ "html_instructions": "Curva suave à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eR. Gomes de Carvalho\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e46&nbsp;m\u003c/b\u003e\u003c/span\u003e",
186
+ "distance": {
187
+ "value": 46,
188
+ "text": "46 m"
189
+ }
190
+ }, {
191
+ "travel_mode": "DRIVING",
192
+ "start_location": {
193
+ "lat": -23.5959300,
194
+ "lng": -46.6877500
195
+ },
196
+ "end_location": {
197
+ "lat": -23.5962400,
198
+ "lng": -46.6879000
199
+ },
200
+ "polyline": {
201
+ "points": "pq_oClu}{G|@\\",
202
+ "levels": "BB"
203
+ },
204
+ "duration": {
205
+ "value": 13,
206
+ "text": "1 min"
207
+ },
208
+ "html_instructions": "Vire à \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eR. Tenerife\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e38&nbsp;m\u003c/b\u003e\u003c/span\u003e\u003cdiv style=\"font-size:0.9em\"\u003eO destino estará à esquerda\u003c/div\u003e",
209
+ "distance": {
210
+ "value": 38,
211
+ "text": "38 m"
212
+ }
213
+ } ],
214
+ "duration": {
215
+ "value": 759,
216
+ "text": "13 minutos"
217
+ },
218
+ "distance": {
219
+ "value": 5608,
220
+ "text": "5,6 km"
221
+ },
222
+ "start_location": {
223
+ "lat": -23.5642400,
224
+ "lng": -46.6792200
225
+ },
226
+ "end_location": {
227
+ "lat": -23.5962400,
228
+ "lng": -46.6879000
229
+ },
230
+ "start_address": "R. dos Pinheiros, 100 - Pinheiros, São Paulo, 05422-000, Brasil",
231
+ "end_address": "R. Tenerife, 31 - Itaim Bibi, São Paulo, 04548-040, Brasil"
232
+ } ],
233
+ "copyrights": "Map data ©2010 MapLink",
234
+ "overview_polyline": {
235
+ "points": "nkynCb`|{G@qA`@kAr]px@nGhPBr@Mh@kBjAkClAAr@bJ}E~ByApl@i[~EuBpCw@xTmIpF}@zJcCdIsAxR_EvLqBdBhJTjBB`@YfBvBfN|AlHe@nA|@\\",
236
+ "levels": "B?@?@????A?????@????A???????B"
237
+ },
238
+ "warnings": [ ],
239
+ "waypoint_order": [ ]
240
+ } ]
241
+ }
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GoMaps::CEP do
4
+ context 'given valid cep' do
5
+ before :each do
6
+ map_url_to_file 'http://www.buscarcep.com.br/?formato=xml&cep=01310-000', 'cep_success'
7
+ @cep = GoMaps::CEP.new('01310-000')
8
+ end
9
+
10
+ context 'on #street' do
11
+ it 'should return the street' do
12
+ @cep.street.should eql('Avenida Paulista')
13
+ end
14
+ end
15
+
16
+ context 'on #city' do
17
+ it 'should return the city' do
18
+ @cep.city.should eql('São Paulo')
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'given invalid cep' do
24
+ it 'should raise AddressNotFoundException' do
25
+ map_url_to_file 'http://www.buscarcep.com.br/?formato=xml&cep=12345-678', 'cep_error'
26
+ lambda { @cep = GoMaps::CEP.new('12345-678') }.should raise_error(GoMaps::AddressNotFoundException)
27
+ end
28
+ end
29
+ end
@@ -1,21 +1,39 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe GoMaps::Direction do
4
- context 'on #to_map' do
5
- before :each do
6
- @address1, @address2 = 'Invalid Address 1', 'Invalid Address 2'
7
- end
4
+ before :each do
5
+ @address1, @address2 = 'Valid Address 1', 'Valid Address 2'
6
+ @direction = GoMaps::Direction.new(:from => @address1, :to => @address2)
7
+ end
8
8
 
9
+ context 'on #to_map' do
9
10
  it 'should return a map' do
10
- GoMaps::Direction.new(:from => @address1, :to => @address2).to_map.should eql("<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?ie=UTF8&output=embed&saddr=#{@address1}&daddr=#{@address2}'></iframe>")
11
+ @direction.to_map.should eql("<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?ie=UTF8&output=embed&saddr=#{@address1}&daddr=#{@address2}'></iframe>")
11
12
  end
12
13
 
13
14
  it 'should accept width as an option' do
14
- GoMaps::Direction.new(:from => @address1, :to => @address2).to_map(:width => 333).include?('width=\'333\'').should be_true
15
+ @direction.to_map(:width => 333).include?('width=\'333\'').should be_true
15
16
  end
16
17
 
17
18
  it 'should accept height as an option' do
18
- GoMaps::Direction.new(:from => @address1, :to => @address2).to_map(:height => 444).include?('height=\'444\'').should be_true
19
+ @direction.to_map(:height => 444).include?('height=\'444\'').should be_true
20
+ end
21
+ end
22
+
23
+ context 'on #to_html' do
24
+ it 'should return an html' do
25
+ map_addresses_to_file(@address1, @address2, 'direction_success')
26
+ @direction.to_html.include?('Head <b>north</b> on <b>Av. Vinte e Três de Maio</b>').should be_true
27
+ end
28
+
29
+ it 'should return an html with a language specified' do
30
+ map_addresses_to_file(@address1, @address2, 'direction_success_pt-BR', :language => 'pt-BR')
31
+ @direction.to_html(:language => 'pt-BR').include?('Siga na direção <b>leste</b> na <b>R. dos Pinheiros</b>').should be_true
32
+ end
33
+
34
+ it 'should raise an address not found expection' do
35
+ map_addresses_to_file(@address1, @address2, 'direction_error')
36
+ lambda { @direction.to_html }.should raise_error(GoMaps::AddressNotFoundException)
19
37
  end
20
38
  end
21
39
  end
data/spec/spec_helper.rb CHANGED
@@ -10,8 +10,9 @@ Spec::Runner.configure do |config|
10
10
  FakeWeb.allow_net_connect = false
11
11
  end
12
12
 
13
- def map_addresses_to_file(address1, address2, file_name)
14
- map_query_string_to_file "origin=#{address1}&destination=#{address2}", file_name
13
+ def map_addresses_to_file(address1, address2, file_name, options = {})
14
+ options[:language] ||= "en"
15
+ map_query_string_to_file "origin=#{address1}&destination=#{address2}&language=#{options[:language]}", file_name
15
16
  end
16
17
 
17
18
  def map_address_to_file(address, file_name)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gonow
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-13 00:00:00 -03:00
17
+ date: 2010-07-16 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,20 @@ dependencies:
59
59
  version: 0.1.6
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 4
72
+ - 1
73
+ version: 1.4.1
74
+ type: :runtime
75
+ version_requirements: *id004
62
76
  description: Ruby API to geographic operations
63
77
  email:
64
78
  executables: []
@@ -75,12 +89,19 @@ files:
75
89
  - lib/go_maps.rb
76
90
  - lib/go_maps/address.rb
77
91
  - lib/go_maps/address_not_found_exception.rb
92
+ - lib/go_maps/cep.rb
78
93
  - lib/go_maps/direction.rb
79
94
  - spec/data/address_error
80
95
  - spec/data/address_success
96
+ - spec/data/cep_error
97
+ - spec/data/cep_success
98
+ - spec/data/direction_error
99
+ - spec/data/direction_success
100
+ - spec/data/direction_success_pt-BR
81
101
  - spec/data/distance_error
82
102
  - spec/data/distance_success_10.8
83
103
  - spec/go_maps/address_spec.rb
104
+ - spec/go_maps/cep_spec.rb
84
105
  - spec/go_maps/direction_spec.rb
85
106
  - spec/spec.opts
86
107
  - spec/spec_helper.rb
@@ -116,5 +137,6 @@ specification_version: 3
116
137
  summary: Ruby API to geographic operations
117
138
  test_files:
118
139
  - spec/go_maps/address_spec.rb
140
+ - spec/go_maps/cep_spec.rb
119
141
  - spec/go_maps/direction_spec.rb
120
142
  - spec/spec_helper.rb