google-maps 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.travis.yml +2 -2
- data/README.md +9 -0
- data/google-maps.gemspec +4 -6
- data/lib/google-maps.rb +5 -0
- data/lib/google_maps/api.rb +5 -5
- data/lib/google_maps/configuration.rb +11 -9
- data/lib/google_maps/distance_matrix.rb +40 -0
- data/lib/google_maps/place.rb +3 -3
- data/lib/google_maps/version.rb +1 -1
- data/spec/fixtures/distance-matrix.json +22 -0
- data/spec/google_maps/api_spec.rb +2 -2
- data/spec/google_maps/distance_matrix_spec.rb +16 -0
- metadata +20 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63fbd8b11238001389fff8a0e84bb1fa0c9fea0f674792ca4fd5a6d7fcb1b8a5
|
4
|
+
data.tar.gz: 2dd65ff3cccabe859ac5cd12689ff2e0c039020e3ee631539e46ba22163e4124
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58d772e216fb6a200a74e10391550e14f57d81e8854b5e3e97ac409c0d4d057428656413e49718381077ca9589b640a6f7728a5f2ec7abb5263243c3712cb00
|
7
|
+
data.tar.gz: 3993629575a01844bfc9164bffa6015577a029549da06f7bb256ed84ec429fa718615ba78743c4c31ab0f149aa3af3fd19fbf17f7d00ecac8783ff24062ab3f9
|
data/.rubocop.yml
CHANGED
@@ -7,7 +7,7 @@ Metrics/BlockLength:
|
|
7
7
|
- "spec/**/*.rb"
|
8
8
|
Max: 80
|
9
9
|
|
10
|
-
|
10
|
+
Layout/LineLength:
|
11
11
|
Max: 130
|
12
12
|
|
13
13
|
Metrics/MethodLength:
|
@@ -22,3 +22,6 @@ Naming/FileName:
|
|
22
22
|
|
23
23
|
Style/Documentation:
|
24
24
|
Enabled: false
|
25
|
+
|
26
|
+
Style/MethodMissingSuper:
|
27
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -66,6 +66,15 @@ end
|
|
66
66
|
#=> "1 hour 12 mins"
|
67
67
|
```
|
68
68
|
|
69
|
+
## Distance matrix
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Google::Maps.distance_matrix("Science Park, Amsterdam", "Deventer").distance
|
73
|
+
#=> 104478
|
74
|
+
Google::Maps.distance_matrix("Science Park, Amsterdam", "Deventer").duration
|
75
|
+
#=> 4374
|
76
|
+
```
|
77
|
+
|
69
78
|
### Route
|
70
79
|
|
71
80
|
```ruby
|
data/google-maps.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
4
|
require 'google_maps/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
@@ -13,21 +13,19 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = 'Ruby wrapper for the Google Maps API'
|
14
14
|
s.description = 'This is a ruby wrapper for the Google Maps api'
|
15
15
|
|
16
|
-
s.rubyforge_project = 'google-maps'
|
17
|
-
|
18
16
|
s.files = `git ls-files`.split("\n")
|
19
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
21
19
|
s.require_paths = ['lib']
|
22
20
|
|
23
|
-
s.add_development_dependency('bundler', '
|
21
|
+
s.add_development_dependency('bundler', '> 1.0')
|
24
22
|
s.add_development_dependency('coveralls', '~> 0.8')
|
25
23
|
s.add_development_dependency('mocha', '~> 1.7.0')
|
26
24
|
s.add_development_dependency('rake', '~> 12.3.2')
|
27
|
-
s.add_development_dependency('rspec', '~> 3.
|
25
|
+
s.add_development_dependency('rspec', '~> 3.9.0')
|
28
26
|
s.add_development_dependency('rspec-collection_matchers', '~> 1.1')
|
29
27
|
s.add_development_dependency('rspec-its', '~> 1.2')
|
30
|
-
s.add_development_dependency('rubocop', '~> 0.
|
28
|
+
s.add_development_dependency('rubocop', '~> 0.79.0')
|
31
29
|
s.add_development_dependency('simplecov', '~> 0.5')
|
32
30
|
s.add_development_dependency('yard', '~> 0.9', '>= 0.9.11')
|
33
31
|
s.add_dependency('hashie', '~> 3.6', '>= 3.6.0')
|
data/lib/google-maps.rb
CHANGED
@@ -5,6 +5,7 @@ require File.expand_path('google_maps/logger', __dir__)
|
|
5
5
|
require File.expand_path('google_maps/route', __dir__)
|
6
6
|
require File.expand_path('google_maps/place', __dir__)
|
7
7
|
require File.expand_path('google_maps/location', __dir__)
|
8
|
+
require File.expand_path('google_maps/distance_matrix', __dir__)
|
8
9
|
|
9
10
|
module Google
|
10
11
|
module Maps
|
@@ -31,6 +32,10 @@ module Google
|
|
31
32
|
PlaceDetails.find(place_id, language)
|
32
33
|
end
|
33
34
|
|
35
|
+
def self.distance_matrix(from, to, options = {})
|
36
|
+
DistanceMatrix.new(from, to, options_with_defaults(options))
|
37
|
+
end
|
38
|
+
|
34
39
|
def self.geocode(address, language = default_language)
|
35
40
|
Location.find(address, language)
|
36
41
|
rescue ZeroResultsException
|
data/lib/google_maps/api.rb
CHANGED
@@ -17,8 +17,8 @@ module Google
|
|
17
17
|
class ZeroResultsException < InvalidResponseException; end
|
18
18
|
|
19
19
|
class API
|
20
|
-
STATUS_OK = 'OK'
|
21
|
-
STATUS_ZERO_RESULTS = 'ZERO_RESULTS'
|
20
|
+
STATUS_OK = 'OK'
|
21
|
+
STATUS_ZERO_RESULTS = 'ZERO_RESULTS'
|
22
22
|
|
23
23
|
class << self
|
24
24
|
def query(service, args = {})
|
@@ -59,9 +59,9 @@ module Google
|
|
59
59
|
def response(url)
|
60
60
|
begin
|
61
61
|
result = Google::Maps::Result.new JSON.parse(HTTPClient.new.get_content(url))
|
62
|
-
rescue StandardError =>
|
63
|
-
Google::Maps.logger.error
|
64
|
-
raise InvalidResponseException, "unknown error: #{
|
62
|
+
rescue StandardError => e
|
63
|
+
Google::Maps.logger.error e.message.to_s
|
64
|
+
raise InvalidResponseException, "unknown error: #{e.message}"
|
65
65
|
end
|
66
66
|
handle_result_status(result.status)
|
67
67
|
result
|
@@ -8,22 +8,23 @@ module Google
|
|
8
8
|
# An array of valid keys in the options hash when configuring an {Google::Maps::API}
|
9
9
|
VALID_OPTIONS_KEYS = %i[
|
10
10
|
end_point authentication_mode client_id client_secret format
|
11
|
-
directions_service places_service geocode_service
|
11
|
+
directions_service places_service geocode_service distance_matrix_service
|
12
12
|
api_key default_language place_details_service default_params
|
13
13
|
].freeze
|
14
14
|
|
15
|
-
API_KEY = 'api_key'
|
16
|
-
DIGITAL_SIGNATURE = 'digital_signature'
|
15
|
+
API_KEY = 'api_key'
|
16
|
+
DIGITAL_SIGNATURE = 'digital_signature'
|
17
17
|
|
18
18
|
# By default, set "https://maps.googleapis.com/maps/api/" as the server
|
19
|
-
DEFAULT_END_POINT = 'https://maps.googleapis.com/maps/api/'
|
19
|
+
DEFAULT_END_POINT = 'https://maps.googleapis.com/maps/api/'
|
20
20
|
|
21
|
-
DEFAULT_DIRECTIONS_SERVICE = 'directions'
|
22
|
-
DEFAULT_PLACES_SERVICE = 'place/autocomplete'
|
23
|
-
DEFAULT_PLACE_DETAILS_SERVICE = 'place/details'
|
24
|
-
DEFAULT_GEOCODE_SERVICE = 'geocode'
|
21
|
+
DEFAULT_DIRECTIONS_SERVICE = 'directions'
|
22
|
+
DEFAULT_PLACES_SERVICE = 'place/autocomplete'
|
23
|
+
DEFAULT_PLACE_DETAILS_SERVICE = 'place/details'
|
24
|
+
DEFAULT_GEOCODE_SERVICE = 'geocode'
|
25
|
+
DEFAULT_DISTANCE_MATRIX_SERVICE = 'distancematrix'
|
25
26
|
|
26
|
-
DEFAULT_FORMAT = 'json'
|
27
|
+
DEFAULT_FORMAT = 'json'
|
27
28
|
|
28
29
|
# default language
|
29
30
|
DEFAULT_LANGUAGE = :en
|
@@ -77,6 +78,7 @@ module Google
|
|
77
78
|
self.places_service = DEFAULT_PLACES_SERVICE
|
78
79
|
self.place_details_service = DEFAULT_PLACE_DETAILS_SERVICE
|
79
80
|
self.geocode_service = DEFAULT_GEOCODE_SERVICE
|
81
|
+
self.distance_matrix_service = DEFAULT_DISTANCE_MATRIX_SERVICE
|
80
82
|
self.default_language = DEFAULT_LANGUAGE
|
81
83
|
self.default_params = DEFAULT_PARAMS
|
82
84
|
self.authentication_mode = nil
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('api', __dir__)
|
4
|
+
|
5
|
+
module Google
|
6
|
+
module Maps
|
7
|
+
class DistanceMatrix
|
8
|
+
attr_accessor :from, :to, :options
|
9
|
+
|
10
|
+
def initialize(from, to, options = {})
|
11
|
+
options = { language: options } unless options.is_a? Hash
|
12
|
+
@from = from
|
13
|
+
@to = to
|
14
|
+
@options = { language: :en }.merge(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def distance
|
18
|
+
element.distance.value
|
19
|
+
end
|
20
|
+
|
21
|
+
def duration
|
22
|
+
element.duration.value
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def element
|
28
|
+
element = distance_matrix.rows.first.elements.first
|
29
|
+
|
30
|
+
raise Google::Maps::ZeroResultsException if element.status == 'NOT_FOUND'
|
31
|
+
|
32
|
+
element
|
33
|
+
end
|
34
|
+
|
35
|
+
def distance_matrix
|
36
|
+
@distance_matrix ||= API.query(:distance_matrix_service, @options.merge(origins: from, destinations: to))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/google_maps/place.rb
CHANGED
@@ -93,13 +93,13 @@ module Google
|
|
93
93
|
|
94
94
|
@address_components.find do |component|
|
95
95
|
component.types.first == method_name.to_s
|
96
|
-
end
|
96
|
+
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def respond_to_missing?(method_name,
|
99
|
+
def respond_to_missing?(method_name, _include_private = false)
|
100
100
|
@address_components.any? do |component|
|
101
101
|
component.types.first == method_name.to_s
|
102
|
-
end
|
102
|
+
end
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
data/lib/google_maps/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"destination_addresses" : [ "Amsterdam" ],
|
3
|
+
"origin_addresses" : [ "Utrecht" ],
|
4
|
+
"rows" : [
|
5
|
+
{
|
6
|
+
"elements" : [
|
7
|
+
{
|
8
|
+
"distance" : {
|
9
|
+
"text" : "53,7 km",
|
10
|
+
"value" : 53744
|
11
|
+
},
|
12
|
+
"duration" : {
|
13
|
+
"text" : "54 min.",
|
14
|
+
"value" : 3237
|
15
|
+
},
|
16
|
+
"status" : "OK"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"status" : "OK"
|
22
|
+
}
|
@@ -28,8 +28,8 @@ describe Google::Maps::API do
|
|
28
28
|
stub_response('zero-results.json')
|
29
29
|
begin
|
30
30
|
Google::Maps.distance('Blah blah', 'Jalala')
|
31
|
-
rescue StandardError =>
|
32
|
-
@error =
|
31
|
+
rescue StandardError => e
|
32
|
+
@error = e
|
33
33
|
ensure
|
34
34
|
expect(@error).not_to be_nil
|
35
35
|
expect(@error).to be_a_kind_of StandardError
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../spec_helper', __dir__)
|
4
|
+
|
5
|
+
describe Google::Maps::DistanceMatrix do
|
6
|
+
describe '.find' do
|
7
|
+
subject { Google::Maps::DistanceMatrix.new('Amsterdam', 'Utrecht') }
|
8
|
+
|
9
|
+
context ':nl' do
|
10
|
+
before { stub_response('distance-matrix.json') }
|
11
|
+
|
12
|
+
its(:distance) { should eq 53_744 }
|
13
|
+
its(:duration) { should eq 3237 }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
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:
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.9.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.9.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec-collection_matchers
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.79.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 0.79.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,22 +160,22 @@ dependencies:
|
|
160
160
|
name: hashie
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- - ">="
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: 3.6.0
|
166
163
|
- - "~>"
|
167
164
|
- !ruby/object:Gem::Version
|
168
165
|
version: '3.6'
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 3.6.0
|
169
169
|
type: :runtime
|
170
170
|
prerelease: false
|
171
171
|
version_requirements: !ruby/object:Gem::Requirement
|
172
172
|
requirements:
|
173
|
-
- - ">="
|
174
|
-
- !ruby/object:Gem::Version
|
175
|
-
version: 3.6.0
|
176
173
|
- - "~>"
|
177
174
|
- !ruby/object:Gem::Version
|
178
175
|
version: '3.6'
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 3.6.0
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
180
|
name: httpclient
|
181
181
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- lib/google-maps.rb
|
243
243
|
- lib/google_maps/api.rb
|
244
244
|
- lib/google_maps/configuration.rb
|
245
|
+
- lib/google_maps/distance_matrix.rb
|
245
246
|
- lib/google_maps/location.rb
|
246
247
|
- lib/google_maps/logger.rb
|
247
248
|
- lib/google_maps/place.rb
|
@@ -253,6 +254,7 @@ files:
|
|
253
254
|
- spec/fixtures/den-haag-nl.json
|
254
255
|
- spec/fixtures/deventer-en.json
|
255
256
|
- spec/fixtures/deventer-nl.json
|
257
|
+
- spec/fixtures/distance-matrix.json
|
256
258
|
- spec/fixtures/geocoder/amsterdam-en.json
|
257
259
|
- spec/fixtures/geocoder/science-park-400-amsterdam-en.json
|
258
260
|
- spec/fixtures/geocoder/science-park-400-amsterdam-nl.json
|
@@ -260,6 +262,7 @@ files:
|
|
260
262
|
- spec/fixtures/place_details.json
|
261
263
|
- spec/fixtures/zero-results.json
|
262
264
|
- spec/google_maps/api_spec.rb
|
265
|
+
- spec/google_maps/distance_matrix_spec.rb
|
263
266
|
- spec/google_maps/logger_spec.rb
|
264
267
|
- spec/google_maps/place_details_spec.rb
|
265
268
|
- spec/google_maps/place_spec.rb
|
@@ -285,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
288
|
- !ruby/object:Gem::Version
|
286
289
|
version: '0'
|
287
290
|
requirements: []
|
288
|
-
rubygems_version: 3.
|
291
|
+
rubygems_version: 3.1.2
|
289
292
|
signing_key:
|
290
293
|
specification_version: 4
|
291
294
|
summary: Ruby wrapper for the Google Maps API
|
@@ -295,6 +298,7 @@ test_files:
|
|
295
298
|
- spec/fixtures/den-haag-nl.json
|
296
299
|
- spec/fixtures/deventer-en.json
|
297
300
|
- spec/fixtures/deventer-nl.json
|
301
|
+
- spec/fixtures/distance-matrix.json
|
298
302
|
- spec/fixtures/geocoder/amsterdam-en.json
|
299
303
|
- spec/fixtures/geocoder/science-park-400-amsterdam-en.json
|
300
304
|
- spec/fixtures/geocoder/science-park-400-amsterdam-nl.json
|
@@ -302,6 +306,7 @@ test_files:
|
|
302
306
|
- spec/fixtures/place_details.json
|
303
307
|
- spec/fixtures/zero-results.json
|
304
308
|
- spec/google_maps/api_spec.rb
|
309
|
+
- spec/google_maps/distance_matrix_spec.rb
|
305
310
|
- spec/google_maps/logger_spec.rb
|
306
311
|
- spec/google_maps/place_details_spec.rb
|
307
312
|
- spec/google_maps/place_spec.rb
|