google-maps 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../spec_helper', __dir__)
4
+
5
+ describe Google::Maps::Route do
6
+ describe 'dutch' do
7
+ before(:each) do
8
+ stub_response('amsterdam-deventer-nl.json')
9
+ @route = Google::Maps::Route.new('Science Park, Amsterdam', 'Deventer', :nl)
10
+ end
11
+
12
+ it 'should be able to calculate a route' do
13
+ expect(@route.distance.text).to eq('104 km')
14
+ expect(@route.duration.text).to eq('1 uur 12 min.')
15
+ expect(@route.distance.value).to eq(103_712)
16
+ expect(@route.duration.value).to eq(4337)
17
+ end
18
+
19
+ it 'should be able to present the text in Dutch' do
20
+ expect(@route.options[:language]).to eq(:nl)
21
+ expect(@route.end_address).to eq('Deventer, Nederland')
22
+ end
23
+
24
+ it 'should be able to return the address for the origin' do
25
+ expect(@route.start_address).to eq('Science Park, 1098 Amsterdam, Nederland')
26
+ end
27
+
28
+ it 'should be able to return the address for the destination' do
29
+ expect(@route.end_address).to eq('Deventer, Nederland')
30
+ end
31
+
32
+ it 'should be able to return the latiude and longitude for the origin' do
33
+ expect(@route.start_location.lat).to eq(52.35445000000001)
34
+ expect(@route.start_location.lng).to eq(4.95420)
35
+ expect(@route.origin_latlong).to eq('52.35445000000001,4.9542')
36
+ end
37
+
38
+ it 'should be able to return the latiude and longitude for the destination' do
39
+ expect(@route.end_location.lat).to eq(52.25441000000001)
40
+ expect(@route.end_location.lng).to eq(6.160470)
41
+ expect(@route.destination_latlong).to eq('52.25441000000001,6.16047')
42
+ end
43
+ end
44
+
45
+ describe 'english' do
46
+ it 'should be able to present the text in English' do
47
+ stub_response('amsterdam-deventer-en.json')
48
+ route = Google::Maps::Route.new('Science Park, Amsterdam', 'Deventer', :en)
49
+ expect(route.options[:language]).to eq(:en)
50
+ expect(route.end_address).to eq('Deventer, The Netherlands')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ describe Google::Maps do
6
+ describe 'Directions' do
7
+ before(:each) do
8
+ stub_response('amsterdam-deventer-en.json')
9
+ end
10
+
11
+ it 'should be able to calculate a route' do
12
+ route = Google::Maps.route('Science Park, Amsterdam', 'Deventer')
13
+ expect(route.class).to eq(Google::Maps::Route)
14
+ expect(route.distance.text).to eq('104 km')
15
+ expect(route.duration.text).to eq('1 hour 12 mins')
16
+ expect(route.distance.value).to eq(103_712)
17
+ expect(route.duration.value).to eq(4337)
18
+ end
19
+
20
+ it 'should be able to calculate the distance' do
21
+ expect(Google::Maps.distance('Science Park, Amsterdam', 'Deventer')).to eq('104 km')
22
+ end
23
+
24
+ it 'should be able to calculate the duration' do
25
+ expect(Google::Maps.duration('Science Park, Amsterdam', 'Deventer')).to eq('1 hour 12 mins')
26
+ end
27
+ end
28
+
29
+ describe 'Places' do
30
+ before(:each) do
31
+ stub_response('deventer-en.json')
32
+ end
33
+
34
+ it 'should find a list of places for a keyword' do
35
+ place = Google::Maps.places('Deventer').first
36
+ expect(place.class).to eq(Google::Maps::Place)
37
+ expect(place.text).to eq('Deventer, The Netherlands')
38
+ expect(place.html).to eq('<strong>Deventer</strong>, The Netherlands')
39
+ end
40
+ end
41
+
42
+ describe 'Geocoder' do
43
+ it 'should lookup a latlong for an address' do
44
+ stub_response('geocoder/science-park-400-amsterdam-en.json')
45
+
46
+ location = Google::Maps.geocode('Science Park 400, Amsterdam').first
47
+ expect(location.class).to eq(Google::Maps::Location)
48
+ expect(location.address).to eq('Science Park Amsterdam 400, University of Amsterdam, 1098 XH Amsterdam, The Netherlands')
49
+ expect(location.latitude).to eq(52.3564490)
50
+ expect(location.longitude).to eq(4.95568890)
51
+
52
+ expect(location.lat_lng).to eq([52.3564490, 4.95568890])
53
+ end
54
+
55
+ it 'should handle multiple location for an address' do
56
+ stub_response('geocoder/amsterdam-en.json')
57
+
58
+ locations = Google::Maps.geocode('Amsterdam')
59
+ expect(locations).to have(2).items
60
+ location = locations.last
61
+ expect(location.address).to eq('Amsterdam, NY, USA')
62
+ expect(location.latitude).to eq(42.93868560)
63
+ expect(location.longitude).to eq(-74.18818580)
64
+ end
65
+
66
+ it 'should accept languages other than en' do
67
+ stub_response('geocoder/science-park-400-amsterdam-nl.json')
68
+
69
+ location = Google::Maps.geocode('Science Park 400, Amsterdam', :nl).first
70
+ expect(location.address).to eq('Science Park 400, Amsterdam, 1098 XH Amsterdam, Nederland')
71
+ end
72
+
73
+ it 'should return an empty array when an address could not be geocoded' do
74
+ stub_response('zero-results.json')
75
+
76
+ expect(Google::Maps.geocode('Amsterdam')).to eq([])
77
+ end
78
+ end
79
+
80
+ describe '.end_point=' do
81
+ it 'should set the end_point' do
82
+ Google::Maps.end_point = 'http://maps.google.com/'
83
+ expect(Google::Maps.end_point).to eq('http://maps.google.com/')
84
+ end
85
+ end
86
+
87
+ describe '.options' do
88
+ it 'should return a hash with the current settings' do
89
+ Google::Maps.end_point = 'test end point'
90
+ Google::Maps.options == { end_point: 'test end point' }
91
+ end
92
+ end
93
+
94
+ describe '.configure' do
95
+ it 'has constants for the authentication methods' do
96
+ expect(Google::Maps::Configuration::API_KEY).to eq 'api_key'
97
+ expect(Google::Maps::Configuration::DIGITAL_SIGNATURE).to eq 'digital_signature'
98
+ end
99
+
100
+ context 'api key configuration' do
101
+ it 'is be possible to set configuration with an api key' do
102
+ Google::Maps.configure do |config|
103
+ config.authentication_mode = Google::Maps::Configuration::API_KEY
104
+ config.api_key = 'xxxxxxxxxxx'
105
+ end
106
+
107
+ expect(Google::Maps.authentication_mode).to eq(Google::Maps::Configuration::API_KEY)
108
+ expect(Google::Maps.api_key).to eq('xxxxxxxxxxx')
109
+ end
110
+
111
+ it 'fails when no api key is provided' do
112
+ expect do
113
+ Google::Maps.configure do |config|
114
+ config.authentication_mode = Google::Maps::Configuration::API_KEY
115
+ end
116
+ end.to raise_error(Google::Maps::InvalidConfigurationError)
117
+ end
118
+ end
119
+
120
+ context 'digital signature configuration' do
121
+ it 'is be possible to set configuration with an api key' do
122
+ Google::Maps.configure do |config|
123
+ config.authentication_mode = Google::Maps::Configuration::DIGITAL_SIGNATURE
124
+ config.client_id = 'xxxxxxxxxxx'
125
+ config.client_secret = 'xxxxxxxxxxx'
126
+ end
127
+
128
+ expect(Google::Maps.authentication_mode).to eq(Google::Maps::Configuration::DIGITAL_SIGNATURE)
129
+ expect(Google::Maps.client_id).to eq('xxxxxxxxxxx')
130
+ expect(Google::Maps.client_secret).to eq('xxxxxxxxxxx')
131
+ end
132
+
133
+ it 'fails when no client id is provided' do
134
+ expect do
135
+ Google::Maps.configure do |config|
136
+ config.authentication_mode = Google::Maps::Configuration::DIGITAL_SIGNATURE
137
+ config.client_secret = 'xxxxxxxxxxx'
138
+ end
139
+ end.to raise_error(Google::Maps::InvalidConfigurationError)
140
+ end
141
+
142
+ it 'fails when no client secret is provided' do
143
+ expect do
144
+ Google::Maps.configure do |config|
145
+ config.authentication_mode = Google::Maps::Configuration::DIGITAL_SIGNATURE
146
+ config.client_id = 'xxxxxxxxxxx'
147
+ end
148
+ end.to raise_error(Google::Maps::InvalidConfigurationError)
149
+ end
150
+ end
151
+
152
+ context 'with invalid authentication mode' do
153
+ it 'raises an invalid configuration exception' do
154
+ expect do
155
+ Google::Maps.configure do |config|
156
+ config.authentication_mode = 'hack'
157
+ config.client_secret = 'xxxxxxxxxxx'
158
+ end
159
+ end.to raise_error(Google::Maps::InvalidConfigurationError)
160
+ end
161
+ end
162
+
163
+ Google::Maps::Configuration::VALID_OPTIONS_KEYS.reject { |x| x == :authentication_mode }.each do |key|
164
+ it "should set the #{key}" do
165
+ Google::Maps.configure do |config|
166
+ config.authentication_mode = Google::Maps::Configuration::API_KEY
167
+ config.api_key = 'xxxxxxxxxxx'
168
+ config.send("#{key}=", key)
169
+ expect(Google::Maps.send(key)).to eq(key)
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'coveralls'
2
4
  Coveralls.wear!
3
5
 
@@ -7,16 +9,13 @@ require 'rspec/collection_matchers'
7
9
  require 'simplecov'
8
10
 
9
11
  SimpleCov.start do
10
- add_group 'GoogleMaps', 'lib/google-maps'
12
+ add_group 'GoogleMaps', 'lib/google_maps'
11
13
  add_group 'Specs', 'spec'
12
14
  add_filter __FILE__
13
15
  end
14
16
 
15
17
  RSpec.configure do |config|
16
18
  config.mock_with :mocha
17
- config.treat_symbols_as_metadata_keys_with_true_values = true
18
- config.filter_run :focus => true
19
- config.run_all_when_everything_filtered = true
20
19
 
21
20
  config.before(:each) do
22
21
  # catch all unmocked requests
@@ -36,7 +35,7 @@ def stub_response(fixture, url = nil)
36
35
  fixture_path = File.expand_path("../fixtures/#{fixture}", __FILE__)
37
36
  expectation = HTTPClient.any_instance.expects(:get_content)
38
37
  expectation.with(url) if url
39
- expectation.returns(File.open(fixture_path, "rb").read)
38
+ expectation.returns(File.open(fixture_path, 'rb').read)
40
39
  end
41
40
 
42
- load File.expand_path('../../lib/google-maps.rb', __FILE__)
41
+ load File.expand_path('../lib/google_maps.rb', __dir__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel van Hoesel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,47 +25,61 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.9'
33
+ version: '0.8'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.9'
40
+ version: '0.8'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.6'
47
+ version: 1.7.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.6'
54
+ version: 1.7.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec-its
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: 12.3.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: 12.3.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.8.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec-collection_matchers
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -81,103 +95,127 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '1.1'
83
97
  - !ruby/object:Gem::Dependency
84
- name: mocha
98
+ name: rspec-its
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.10'
103
+ version: '1.2'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.10'
110
+ version: '1.2'
97
111
  - !ruby/object:Gem::Dependency
98
- name: simplecov
112
+ name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0.5'
117
+ version: 0.61.1
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0.5'
124
+ version: 0.61.1
111
125
  - !ruby/object:Gem::Dependency
112
- name: coveralls
126
+ name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0.8'
131
+ version: '0.5'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0.8'
138
+ version: '0.5'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: yard
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '0.7'
145
+ version: '0.9'
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 0.9.11
132
149
  type: :development
133
150
  prerelease: false
134
151
  version_requirements: !ruby/object:Gem::Requirement
135
152
  requirements:
136
153
  - - "~>"
137
154
  - !ruby/object:Gem::Version
138
- version: '0.7'
155
+ version: '0.9'
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: 0.9.11
139
159
  - !ruby/object:Gem::Dependency
140
- name: json
160
+ name: hashie
141
161
  requirement: !ruby/object:Gem::Requirement
142
162
  requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '3.6'
143
166
  - - ">="
144
167
  - !ruby/object:Gem::Version
145
- version: 1.7.5
168
+ version: 3.6.0
146
169
  type: :runtime
147
170
  prerelease: false
148
171
  version_requirements: !ruby/object:Gem::Requirement
149
172
  requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: '3.6'
150
176
  - - ">="
151
177
  - !ruby/object:Gem::Version
152
- version: 1.7.5
178
+ version: 3.6.0
153
179
  - !ruby/object:Gem::Dependency
154
- name: hashie
180
+ name: httpclient
155
181
  requirement: !ruby/object:Gem::Requirement
156
182
  requirements:
157
183
  - - "~>"
158
184
  - !ruby/object:Gem::Version
159
- version: 2.0.5
185
+ version: '2.7'
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: 2.7.1
160
189
  type: :runtime
161
190
  prerelease: false
162
191
  version_requirements: !ruby/object:Gem::Requirement
163
192
  requirements:
164
193
  - - "~>"
165
194
  - !ruby/object:Gem::Version
166
- version: 2.0.5
195
+ version: '2.7'
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: 2.7.1
167
199
  - !ruby/object:Gem::Dependency
168
- name: httpclient
200
+ name: json
169
201
  requirement: !ruby/object:Gem::Requirement
170
202
  requirements:
171
203
  - - "~>"
172
204
  - !ruby/object:Gem::Version
173
- version: 2.7.1
205
+ version: '2.1'
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 2.1.0
174
209
  type: :runtime
175
210
  prerelease: false
176
211
  version_requirements: !ruby/object:Gem::Requirement
177
212
  requirements:
178
213
  - - "~>"
179
214
  - !ruby/object:Gem::Version
180
- version: 2.7.1
215
+ version: '2.1'
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: 2.1.0
181
219
  - !ruby/object:Gem::Dependency
182
220
  name: ruby-hmac
183
221
  requirement: !ruby/object:Gem::Requirement
@@ -194,26 +232,28 @@ dependencies:
194
232
  version: 0.4.0
195
233
  description: This is a ruby wrapper for the Google Maps api
196
234
  email:
197
- - daniel@danielvanhoesel.nl
235
+ - info@zilverline.com
198
236
  executables: []
199
237
  extensions: []
200
238
  extra_rdoc_files: []
201
239
  files:
202
240
  - ".gitignore"
241
+ - ".rubocop.yml"
203
242
  - ".travis.yml"
204
243
  - Gemfile
205
- - LICENSE.mkd
206
- - README.mkd
244
+ - LICENSE.md
245
+ - README.md
207
246
  - Rakefile
208
247
  - google-maps.gemspec
209
- - lib/google-maps.rb
210
- - lib/google-maps/api.rb
211
- - lib/google-maps/configuration.rb
212
- - lib/google-maps/location.rb
213
- - lib/google-maps/logger.rb
214
- - lib/google-maps/place.rb
215
- - lib/google-maps/route.rb
216
- - lib/google-maps/version.rb
248
+ - lib/google_maps.rb
249
+ - lib/google_maps/api.rb
250
+ - lib/google_maps/configuration.rb
251
+ - lib/google_maps/location.rb
252
+ - lib/google_maps/logger.rb
253
+ - lib/google_maps/place.rb
254
+ - lib/google_maps/result.rb
255
+ - lib/google_maps/route.rb
256
+ - lib/google_maps/version.rb
217
257
  - spec/fixtures/amsterdam-deventer-en.json
218
258
  - spec/fixtures/amsterdam-deventer-nl.json
219
259
  - spec/fixtures/den-haag-nl.json
@@ -225,15 +265,16 @@ files:
225
265
  - spec/fixtures/over_query_limit.json
226
266
  - spec/fixtures/place_details.json
227
267
  - spec/fixtures/zero-results.json
228
- - spec/google-maps/api_spec.rb
229
- - spec/google-maps/logger_spec.rb
230
- - spec/google-maps/place_details_spec.rb
231
- - spec/google-maps/place_spec.rb
232
- - spec/google-maps/route_spec.rb
233
- - spec/google-maps_spec.rb
268
+ - spec/google_maps/api_spec.rb
269
+ - spec/google_maps/logger_spec.rb
270
+ - spec/google_maps/place_details_spec.rb
271
+ - spec/google_maps/place_spec.rb
272
+ - spec/google_maps/route_spec.rb
273
+ - spec/google_maps_spec.rb
234
274
  - spec/spec_helper.rb
235
275
  homepage: http://zilverline.com/
236
- licenses: []
276
+ licenses:
277
+ - MIT
237
278
  metadata: {}
238
279
  post_install_message:
239
280
  rdoc_options: []
@@ -251,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
292
  version: '0'
252
293
  requirements: []
253
294
  rubyforge_project: google-maps
254
- rubygems_version: 2.4.5.1
295
+ rubygems_version: 2.5.2
255
296
  signing_key:
256
297
  specification_version: 4
257
298
  summary: Ruby wrapper for the Google Maps API
@@ -267,11 +308,10 @@ test_files:
267
308
  - spec/fixtures/over_query_limit.json
268
309
  - spec/fixtures/place_details.json
269
310
  - spec/fixtures/zero-results.json
270
- - spec/google-maps/api_spec.rb
271
- - spec/google-maps/logger_spec.rb
272
- - spec/google-maps/place_details_spec.rb
273
- - spec/google-maps/place_spec.rb
274
- - spec/google-maps/route_spec.rb
275
- - spec/google-maps_spec.rb
311
+ - spec/google_maps/api_spec.rb
312
+ - spec/google_maps/logger_spec.rb
313
+ - spec/google_maps/place_details_spec.rb
314
+ - spec/google_maps/place_spec.rb
315
+ - spec/google_maps/route_spec.rb
316
+ - spec/google_maps_spec.rb
276
317
  - spec/spec_helper.rb
277
- has_rdoc: