geogle 0.2.5 → 0.3.1

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.
File without changes
@@ -0,0 +1,59 @@
1
+ describe Geogle::Directions do
2
+ describe 'searching by address' do
3
+ let(:settings) { {} }
4
+ let(:routes) do
5
+ VCR.use_cassette('directions_by_address') do
6
+ described_class.new(settings).routes("Valencia", "Madrid", { region: "es" })
7
+ end
8
+ end
9
+
10
+ it "returns an array" do
11
+ expect(routes).to be_kind_of(Array)
12
+ end
13
+
14
+ it "each element is Geogle::Model::Route" do
15
+ expect(routes.first).to be_kind_of(Geogle::Model::Route)
16
+ end
17
+
18
+ context "when raw is set to true" do
19
+ let(:settings) { { raw: true } }
20
+
21
+ it "returns the raw results in the body in JSON format" do
22
+ expect(routes).to be_kind_of(Array)
23
+ expect(routes.first).to include("legs")
24
+ end
25
+ end
26
+ end
27
+
28
+ describe 'searching by geo-location' do
29
+ let(:routes) do
30
+ VCR.use_cassette('directions_by_latlng') do
31
+ described_class.new.routes("39.4699889,-0.3759178", "40.4167158,-3.7037799", { region: "es" })
32
+ end
33
+ end
34
+
35
+ it "returns an array" do
36
+ expect(routes).to be_kind_of(Array)
37
+ end
38
+
39
+ it "each element is Geogle::Model::Route" do
40
+ expect(routes.first).to be_kind_of(Geogle::Model::Route)
41
+ end
42
+ end
43
+
44
+ describe 'searching by address and no results' do
45
+ let(:routes) do
46
+ VCR.use_cassette('directions_by_address_no_results') do
47
+ described_class.new.routes("Valencia", "New york")
48
+ end
49
+ end
50
+
51
+ it "returns an array" do
52
+ expect(routes).to be_kind_of(Array)
53
+ end
54
+
55
+ it "the array is empty" do
56
+ expect(routes).to be_empty
57
+ end
58
+ end
59
+ end
@@ -1,14 +1,28 @@
1
1
  describe Geogle::Geocoder do
2
2
  describe 'searching by address' do
3
+ let(:settings) { {} }
3
4
  let(:places) do
4
5
  VCR.use_cassette('geocode_by_address') do
5
- described_class.new.address('Valencia', { country: 'ES' })
6
+ described_class.new(settings).address('Valencia', { country: 'ES' })
6
7
  end
7
8
  end
8
9
 
9
10
  it "returns an array" do
10
11
  expect(places).to be_kind_of(Array)
11
12
  end
13
+
14
+ it "each element is Geogle::Model::Place" do
15
+ expect(places.first).to be_kind_of(Geogle::Model::Place)
16
+ end
17
+
18
+ context "when raw is set to true" do
19
+ let(:settings) { { raw: true } }
20
+
21
+ it "returns the raw results in the body in JSON format" do
22
+ expect(places).to be_kind_of(Array)
23
+ expect(places.first).to include("geometry")
24
+ end
25
+ end
12
26
  end
13
27
 
14
28
  describe 'searching with a non-default locale' do
@@ -21,6 +35,10 @@ describe Geogle::Geocoder do
21
35
  it "returns an array" do
22
36
  expect(places).to be_kind_of(Array)
23
37
  end
38
+
39
+ it "each element is Geogle::Model::Place" do
40
+ expect(places.first).to be_kind_of(Geogle::Model::Place)
41
+ end
24
42
  end
25
43
 
26
44
  describe 'searching by latlng' do
@@ -1,150 +1,324 @@
1
1
  describe 'Parser' do
2
- let(:places) do
3
- VCR.use_cassette('geocode_by_latlng') do
4
- Geogle::Geocoder.new.latlng(39.4699075, -0.3762881)
5
- end
6
- end
7
-
8
- it "returns an array of Geogle::Model::Places" do
9
- expect(places).to be_kind_of(Array)
10
- end
11
2
 
12
- it "each element is Geogle::Model::Place" do
13
- expect(places.first).to be_kind_of(Geogle::Model::Place)
14
- end
15
-
16
- describe "place" do
17
- let(:place) { places.first }
18
-
19
- it "geo_location" do
20
- expect(place.geo_location.to_s).to eq("39.4701016,-0.3761823")
3
+ describe "places" do
4
+ let(:places) do
5
+ VCR.use_cassette('geocode_by_latlng') do
6
+ Geogle::Geocoder.new.latlng(39.4699075, -0.3762881)
7
+ end
21
8
  end
22
9
 
23
- it "street" do
24
- expect(place.street).to eq("Plaza Ayuntamiento")
10
+ it "returns an array of Geogle::Model::Places" do
11
+ expect(places).to be_kind_of(Array)
25
12
  end
26
13
 
27
- it "locality" do
28
- expect(place.locality).to eq("Valencia")
14
+ it "each element is Geogle::Model::Place" do
15
+ expect(places.first).to be_kind_of(Geogle::Model::Place)
29
16
  end
30
17
 
31
- it "city" do
32
- expect(place.city).to eq("Valencia")
33
- end
18
+ describe "place" do
19
+ let(:place) { places.first }
34
20
 
35
- it "state" do
36
- expect(place.state).to eq("Valencian Community")
37
- end
21
+ it "geo_location" do
22
+ expect(place.geo_location.to_s).to eq("39.4701016,-0.3761823")
23
+ end
38
24
 
39
- it "country" do
40
- expect(place.country).to eq("Spain")
41
- end
25
+ it "street" do
26
+ expect(place.street).to eq("Plaza Ayuntamiento")
27
+ end
42
28
 
43
- it "country_code" do
44
- expect(place.country_code).to eq("ES")
45
- end
29
+ it "locality" do
30
+ expect(place.locality).to eq("Valencia")
31
+ end
46
32
 
47
- describe "geometry" do
48
- let(:geometry) { place.geometry }
33
+ it "city" do
34
+ expect(place.city).to eq("Valencia")
35
+ end
49
36
 
50
- it "location_type" do
51
- expect(geometry.location_type).to eq("ROOFTOP")
37
+ it "state" do
38
+ expect(place.state).to eq("Valencian Community")
52
39
  end
53
40
 
54
- describe "location" do
55
- let(:location) { geometry.location }
41
+ it "country" do
42
+ expect(place.country).to eq("Spain")
43
+ end
44
+
45
+ it "country_code" do
46
+ expect(place.country_code).to eq("ES")
47
+ end
48
+
49
+ describe "geometry" do
50
+ let(:geometry) { place.geometry }
56
51
 
57
- it "has latitude" do
58
- expect(location.lat).to eq(39.4701016)
52
+ it "location_type" do
53
+ expect(geometry.location_type).to eq("ROOFTOP")
59
54
  end
60
55
 
61
- it "has longitude" do
62
- expect(location.lng).to eq(-0.3761823)
56
+ describe "location" do
57
+ let(:location) { geometry.location }
58
+
59
+ it "has latitude" do
60
+ expect(location.lat).to eq(39.4701016)
61
+ end
62
+
63
+ it "has longitude" do
64
+ expect(location.lng).to eq(-0.3761823)
65
+ end
66
+
67
+ it "to_s" do
68
+ expect(location.to_s).to eq("39.4701016,-0.3761823")
69
+ end
70
+ end
71
+
72
+ describe "bounds" do
73
+ let(:bounds) { geometry.bounds }
74
+
75
+ it "they are nil when there are not" do
76
+ expect(bounds).to be_nil
77
+ end
63
78
  end
64
79
 
65
- it "to_s" do
66
- expect(location.to_s).to eq("39.4701016,-0.3761823")
80
+ describe "viewport" do
81
+ let(:viewport) { geometry.viewport }
82
+
83
+ describe "southwest" do
84
+ let(:southwest) { viewport.southwest }
85
+
86
+ it "has latitude" do
87
+ expect(southwest.lat).to eq(39.4687526197085)
88
+ end
89
+
90
+ it "has longitude" do
91
+ expect(southwest.lng).to eq(-0.3775312802915021)
92
+ end
93
+ end
94
+
95
+ describe "northeast" do
96
+ let(:northeast) { viewport.northeast }
97
+
98
+ it "has latitude" do
99
+ expect(northeast.lat).to eq(39.4714505802915)
100
+ end
101
+
102
+ it "has longitude" do
103
+ expect(northeast.lng).to eq(-0.374833319708498)
104
+ end
105
+ end
67
106
  end
68
107
  end
69
108
 
70
- describe "bounds" do
71
- let(:bounds) { geometry.bounds }
109
+ describe "address" do
110
+ let(:address) { place.address }
111
+
112
+ it "has a street_number" do
113
+ expect(address.street_number).to eq("S/N")
114
+ end
115
+
116
+ it "has a street" do
117
+ expect(address.street).to eq("Plaza Ayuntamiento")
118
+ end
119
+
120
+ it "has a locality" do
121
+ expect(address.locality).to eq("Valencia")
122
+ end
72
123
 
73
- it "they are nil when there are not" do
74
- expect(bounds).to be_nil
124
+ it "has a area_level_1" do
125
+ expect(address.area_level_1).to eq("Valencian Community")
75
126
  end
127
+
128
+ it "has a area_level_1_code" do
129
+ expect(address.area_level_1_code).to eq("Valencian Community")
130
+ end
131
+
132
+ it "has a area_level_2" do
133
+ expect(address.area_level_2).to eq("Valencia")
134
+ end
135
+
136
+ it "has a area_level_2_code" do
137
+ expect(address.area_level_2_code).to eq("V")
138
+ end
139
+
140
+ it "has a country" do
141
+ expect(address.country).to eq("Spain")
142
+ end
143
+
144
+ it "has a country_code" do
145
+ expect(address.country_code).to eq("ES")
146
+ end
147
+
148
+ it "has a formatted" do
149
+ expect(address.formatted).to eq("Plaza Ayuntamiento, S/N, 46002 Valencia, Valencia, Spain")
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ describe 'routes' do
156
+ let(:routes) do
157
+ VCR.use_cassette('directions_by_address') do
158
+ Geogle::Directions.new.routes("Valencia", "Madrid", { region: "es" })
159
+ end
160
+ end
161
+
162
+ it "returns an array" do
163
+ expect(routes).to be_kind_of(Array)
164
+ end
165
+
166
+ it "each element is Geogle::Model::Route" do
167
+ expect(routes.first).to be_kind_of(Geogle::Model::Route)
168
+ end
169
+
170
+ describe "route" do
171
+ let(:route) { routes.first }
172
+
173
+ it "summary" do
174
+ expect(route.summary).to eq("A-3")
175
+ end
176
+
177
+ describe "overview_polyline" do
178
+ pending
179
+ end
180
+
181
+ it "copyrights" do
182
+ expect(route.copyrights).to eq("Map data ©2014 Google, basado en BCN IGN España")
183
+ end
184
+
185
+ describe "warnings" do
186
+ pending
76
187
  end
77
188
 
78
- describe "viewport" do
79
- let(:viewport) { geometry.viewport }
189
+ it "waypoint_order" do
190
+ pending
191
+ expect(route.waypoint_order).to be_kind_of([])
192
+ end
193
+
194
+ describe "bounds" do
195
+ let(:bounds) { route.bounds }
80
196
 
81
197
  describe "southwest" do
82
- let(:southwest) { viewport.southwest }
198
+ let(:southwest) { bounds.southwest }
83
199
 
84
200
  it "has latitude" do
85
- expect(southwest.lat).to eq(39.4687526197085)
201
+ expect(southwest.lat).to eq(39.4289182)
86
202
  end
87
203
 
88
204
  it "has longitude" do
89
- expect(southwest.lng).to eq(-0.3775312802915021)
205
+ expect(southwest.lng).to eq(-3.7046622)
90
206
  end
91
207
  end
92
208
 
93
209
  describe "northeast" do
94
- let(:northeast) { viewport.northeast }
210
+ let(:northeast) { bounds.northeast }
95
211
 
96
212
  it "has latitude" do
97
- expect(northeast.lat).to eq(39.4714505802915)
213
+ expect(northeast.lat).to eq(40.4167158)
98
214
  end
99
215
 
100
216
  it "has longitude" do
101
- expect(northeast.lng).to eq(-0.374833319708498)
217
+ expect(northeast.lng).to eq(-0.3759178)
102
218
  end
103
219
  end
104
220
  end
105
- end
106
221
 
107
- describe "address" do
108
- let(:address) { place.address }
222
+ describe "legs" do
223
+ let(:leg) { route.legs.first }
109
224
 
110
- it "has a street_number" do
111
- expect(address.street_number).to eq("S/N")
112
- end
225
+ it "is an array" do
226
+ expect(route.legs).to be_kind_of(Array)
227
+ end
113
228
 
114
- it "has a street" do
115
- expect(address.street).to eq("Plaza Ayuntamiento")
116
- end
229
+ it "start_address" do
230
+ expect(leg.start_address).to eq("Valencia, Valencia, Spain")
231
+ end
117
232
 
118
- it "has a locality" do
119
- expect(address.locality).to eq("Valencia")
120
- end
233
+ it "end_address" do
234
+ expect(leg.end_address).to eq("Madrid, Madrid, Spain")
235
+ end
121
236
 
122
- it "has a area_level_1" do
123
- expect(address.area_level_1).to eq("Valencian Community")
124
- end
237
+ it "start_location" do
238
+ expect(leg.start_location.to_s).to eq("39.4699889,-0.3759178")
239
+ end
125
240
 
126
- it "has a area_level_1_code" do
127
- expect(address.area_level_1_code).to eq("Valencian Community")
128
- end
241
+ it "end_location" do
242
+ expect(leg.end_location.to_s).to eq("40.4167158,-3.7037799")
243
+ end
129
244
 
130
- it "has a area_level_2" do
131
- expect(address.area_level_2).to eq("Valencia")
132
- end
245
+ describe "distance" do
246
+ let(:distance) { leg.distance }
133
247
 
134
- it "has a area_level_2_code" do
135
- expect(address.area_level_2_code).to eq("V")
136
- end
248
+ it "value" do
249
+ expect(distance.value).to eq(355097)
250
+ end
137
251
 
138
- it "has a country" do
139
- expect(address.country).to eq("Spain")
140
- end
252
+ it "text" do
253
+ expect(distance.text).to eq("355 km")
254
+ end
255
+ end
141
256
 
142
- it "has a country_code" do
143
- expect(address.country_code).to eq("ES")
144
- end
257
+ describe "duration" do
258
+ let(:duration) { leg.duration }
259
+
260
+ it "value" do
261
+ expect(duration.value).to eq(11866)
262
+ end
263
+
264
+ it "text" do
265
+ expect(duration.text).to eq("3 hours 18 mins")
266
+ end
267
+ end
268
+
269
+ describe "arrival_time" do
270
+ let(:arrival_time) { leg.arrival_time }
271
+ pending
272
+ end
145
273
 
146
- it "has a formatted" do
147
- expect(address.formatted).to eq("Plaza Ayuntamiento, S/N, 46002 Valencia, Valencia, Spain")
274
+ describe "departure_time" do
275
+ let(:departure_time) { leg.departure_time }
276
+ pending
277
+ end
278
+
279
+ describe "steps" do
280
+ let(:step) { leg.steps.first }
281
+
282
+ it "is an array" do
283
+ expect(route.legs).to be_kind_of(Array)
284
+ end
285
+
286
+ it "html_instructions" do
287
+ expect(step.html_instructions).to eq("Head <b>north</b> on <b>Plaça de l'Ajuntament</b>")
288
+ end
289
+
290
+ it "travel_mode" do
291
+ expect(step.travel_mode).to eq("DRIVING")
292
+ end
293
+
294
+ it "start_location" do
295
+ expect(step.start_location.to_s).to eq("39.4699889,-0.3759178")
296
+ end
297
+
298
+ it "end_location" do
299
+ expect(step.end_location.to_s).to eq("39.4701816,-0.3759889")
300
+ end
301
+
302
+ describe "distance" do
303
+ it "value" do
304
+ expect(step.distance.value).to eq(22)
305
+ end
306
+
307
+ it "text" do
308
+ expect(step.distance.text).to eq("22 m")
309
+ end
310
+ end
311
+
312
+ describe "duration" do
313
+ it "value" do
314
+ expect(step.duration.value).to eq(2)
315
+ end
316
+
317
+ it "text" do
318
+ expect(step.duration.text).to eq("1 min")
319
+ end
320
+ end
321
+ end
148
322
  end
149
323
  end
150
324
  end