google_distance_matrix 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.editorconfig +16 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +2 -0
- data/Rakefile +9 -4
- data/google_distance_matrix.gemspec +20 -18
- data/lib/google_distance_matrix/client.rb +32 -18
- data/lib/google_distance_matrix/client_cache.rb +9 -3
- data/lib/google_distance_matrix/configuration.rb +37 -19
- data/lib/google_distance_matrix/errors.rb +6 -3
- data/lib/google_distance_matrix/log_subscriber.rb +14 -14
- data/lib/google_distance_matrix/logger.rb +6 -4
- data/lib/google_distance_matrix/matrix.rb +45 -22
- data/lib/google_distance_matrix/place.rb +32 -25
- data/lib/google_distance_matrix/places.rb +5 -4
- data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
- data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +11 -4
- data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
- data/lib/google_distance_matrix/railtie.rb +4 -1
- data/lib/google_distance_matrix/route.rb +22 -15
- data/lib/google_distance_matrix/routes_finder.rb +25 -29
- data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
- data/lib/google_distance_matrix/url_builder.rb +44 -16
- data/lib/google_distance_matrix/version.rb +3 -1
- data/lib/google_distance_matrix.rb +25 -23
- data/spec/lib/google_distance_matrix/client_cache_spec.rb +26 -11
- data/spec/lib/google_distance_matrix/client_spec.rb +40 -30
- data/spec/lib/google_distance_matrix/configuration_spec.rb +36 -24
- data/spec/lib/google_distance_matrix/log_subscriber_spec.rb +13 -44
- data/spec/lib/google_distance_matrix/logger_spec.rb +16 -13
- data/spec/lib/google_distance_matrix/matrix_spec.rb +90 -57
- data/spec/lib/google_distance_matrix/place_spec.rb +30 -25
- data/spec/lib/google_distance_matrix/places_spec.rb +29 -28
- data/spec/lib/google_distance_matrix/polyline_encoder/delta_spec.rb +5 -3
- data/spec/lib/google_distance_matrix/polyline_encoder_spec.rb +7 -2
- data/spec/lib/google_distance_matrix/route_spec.rb +11 -9
- data/spec/lib/google_distance_matrix/routes_finder_spec.rb +95 -81
- data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
- data/spec/spec_helper.rb +3 -1
- metadata +35 -7
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::UrlBuilder do
|
4
6
|
let(:delimiter) { described_class::DELIMITER }
|
5
|
-
let(:comma) { CGI.escape
|
6
|
-
let(:colon) { CGI.escape
|
7
|
+
let(:comma) { CGI.escape ',' }
|
8
|
+
let(:colon) { CGI.escape ':' }
|
7
9
|
|
8
|
-
let(:origin_1) { GoogleDistanceMatrix::Place.new address:
|
9
|
-
let(:origin_2) { GoogleDistanceMatrix::Place.new address:
|
10
|
+
let(:origin_1) { GoogleDistanceMatrix::Place.new address: 'address_origin_1' }
|
11
|
+
let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'address_origin_2' }
|
10
12
|
|
11
13
|
let(:destination_1) { GoogleDistanceMatrix::Place.new lat: 1, lng: 11 }
|
12
14
|
let(:destination_2) { GoogleDistanceMatrix::Place.new lat: 2, lng: 22 }
|
@@ -14,74 +16,77 @@ describe GoogleDistanceMatrix::UrlBuilder do
|
|
14
16
|
let(:origins) { [origin_1, origin_2] }
|
15
17
|
let(:destinations) { [destination_1, destination_2] }
|
16
18
|
|
19
|
+
let(:config) { GoogleDistanceMatrix::Configuration.new }
|
20
|
+
|
17
21
|
let(:matrix) do
|
18
22
|
GoogleDistanceMatrix::Matrix.new(
|
19
23
|
origins: origins,
|
20
|
-
destinations: destinations
|
24
|
+
destinations: destinations,
|
25
|
+
configuration: config
|
21
26
|
)
|
22
27
|
end
|
23
28
|
|
24
29
|
subject { described_class.new matrix }
|
25
30
|
|
26
|
-
describe
|
27
|
-
it
|
31
|
+
describe '#initialize' do
|
32
|
+
it 'has a matrix' do
|
28
33
|
expect(described_class.new(matrix).matrix).to eq matrix
|
29
34
|
end
|
30
35
|
|
31
|
-
it
|
32
|
-
expect
|
36
|
+
it 'fails if matrix is invalid' do
|
37
|
+
expect do
|
33
38
|
described_class.new GoogleDistanceMatrix::Matrix.new
|
34
|
-
|
39
|
+
end.to raise_error GoogleDistanceMatrix::InvalidMatrix
|
35
40
|
end
|
36
41
|
|
37
42
|
it "fails if matrix's configuration is invalid" do
|
38
|
-
expect
|
43
|
+
expect do
|
39
44
|
matrix.configure { |c| c.mode = 'foobar' }
|
40
45
|
described_class.new matrix
|
41
|
-
|
46
|
+
end.to raise_error GoogleDistanceMatrix::InvalidMatrix
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
50
|
+
describe '#sensitive_url' do
|
51
|
+
it 'fails if the url is more than 2048 characters' do
|
52
|
+
long_string = ''.dup
|
53
|
+
2049.times { long_string << 'a' }
|
45
54
|
|
46
|
-
|
47
|
-
it "fails if the url is more than 2048 characters" do
|
48
|
-
long_string = ""
|
49
|
-
2049.times { long_string << "a" }
|
50
|
-
|
51
|
-
allow(subject).to receive(:get_params_string).and_return long_string
|
55
|
+
expect(subject).to receive(:query_params_string).and_return long_string
|
52
56
|
|
53
|
-
expect { subject.
|
57
|
+
expect { subject.sensitive_url }.to raise_error GoogleDistanceMatrix::MatrixUrlTooLong
|
54
58
|
end
|
55
59
|
|
56
|
-
it
|
57
|
-
expect(subject.
|
60
|
+
it 'starts with the base URL' do
|
61
|
+
expect(subject.sensitive_url).to start_with 'https://' + described_class::BASE_URL
|
58
62
|
end
|
59
63
|
|
60
|
-
it
|
61
|
-
matrix.configure { |c| c.protocol =
|
62
|
-
expect(subject.
|
64
|
+
it 'has a configurable protocol' do
|
65
|
+
matrix.configure { |c| c.protocol = 'http' }
|
66
|
+
expect(subject.sensitive_url).to start_with 'http://'
|
63
67
|
end
|
64
68
|
|
65
|
-
it
|
66
|
-
expect(subject.
|
69
|
+
it 'includes origins' do
|
70
|
+
expect(subject.sensitive_url)
|
71
|
+
.to include "origins=address_origin_1#{delimiter}address_origin_2"
|
67
72
|
end
|
68
73
|
|
69
|
-
it
|
70
|
-
expect(subject.
|
74
|
+
it 'includes destinations' do
|
75
|
+
expect(subject.sensitive_url).to include "destinations=1#{comma}11#{delimiter}2#{comma}22"
|
71
76
|
end
|
72
77
|
|
73
|
-
describe
|
74
|
-
let(:destination_1) { GoogleDistanceMatrix::Place.new lat: 10.123456789, lng:
|
78
|
+
describe 'lat lng scale' do
|
79
|
+
let(:destination_1) { GoogleDistanceMatrix::Place.new lat: 10.123456789, lng: '10.987654321' }
|
75
80
|
|
76
|
-
it
|
81
|
+
it 'rounds lat and lng' do
|
77
82
|
subject.matrix.configure { |c| c.lat_lng_scale = 5 }
|
78
83
|
|
79
|
-
expect(subject.
|
84
|
+
expect(subject.sensitive_url).to include "destinations=10.12346#{comma}10.98765"
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
83
|
-
describe
|
84
|
-
let(:destination_3) { GoogleDistanceMatrix::Place.new address:
|
88
|
+
describe 'use encoded polylines' do
|
89
|
+
let(:destination_3) { GoogleDistanceMatrix::Place.new address: 'address_destination_3' }
|
85
90
|
let(:destination_4) { GoogleDistanceMatrix::Place.new lat: 4, lng: 44 }
|
86
91
|
let(:destinations) { [destination_1, destination_2, destination_3, destination_4] }
|
87
92
|
|
@@ -89,12 +94,15 @@ describe GoogleDistanceMatrix::UrlBuilder do
|
|
89
94
|
matrix.configure { |c| c.use_encoded_polylines = true }
|
90
95
|
end
|
91
96
|
|
92
|
-
it
|
93
|
-
expect(subject.
|
97
|
+
it 'includes places with addresses as addresses' do
|
98
|
+
expect(subject.sensitive_url)
|
99
|
+
.to include "origins=address_origin_1#{delimiter}address_origin_2"
|
94
100
|
end
|
95
101
|
|
96
|
-
it
|
97
|
-
|
102
|
+
it(
|
103
|
+
'encodes places with lat/lng values togheter, broken up by addresses to keep places order'
|
104
|
+
) do
|
105
|
+
expect(subject.sensitive_url).to include(
|
98
106
|
# 2 first places encoded togheter as they have lat lng values
|
99
107
|
"destinations=enc#{colon}_ibE_mcbA_ibE_mcbA#{colon}#{delimiter}" +
|
100
108
|
# encoded polyline broken off by a destination with address
|
@@ -105,7 +113,7 @@ describe GoogleDistanceMatrix::UrlBuilder do
|
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
108
|
-
describe
|
116
|
+
describe 'configuration' do
|
109
117
|
context 'with google api key set' do
|
110
118
|
before do
|
111
119
|
matrix.configure do |config|
|
@@ -114,26 +122,67 @@ describe GoogleDistanceMatrix::UrlBuilder do
|
|
114
122
|
end
|
115
123
|
|
116
124
|
it 'includes the api key' do
|
117
|
-
expect(subject.
|
125
|
+
expect(subject.sensitive_url).to include "key=#{matrix.configuration.google_api_key}"
|
118
126
|
end
|
119
127
|
end
|
120
128
|
|
121
|
-
context
|
129
|
+
context 'with google business client id and private key set' do
|
122
130
|
before do
|
123
131
|
matrix.configure do |config|
|
124
|
-
config.google_business_api_client_id =
|
125
|
-
config.google_business_api_private_key =
|
132
|
+
config.google_business_api_client_id = '123'
|
133
|
+
config.google_business_api_private_key = 'c2VjcmV0'
|
126
134
|
end
|
127
135
|
end
|
128
136
|
|
129
|
-
it
|
130
|
-
expect(subject.
|
137
|
+
it 'includes client' do
|
138
|
+
expect(subject.sensitive_url)
|
139
|
+
.to include "client=#{matrix.configuration.google_business_api_client_id}"
|
131
140
|
end
|
132
141
|
|
133
|
-
it
|
134
|
-
expect(subject.
|
142
|
+
it 'has signature' do
|
143
|
+
expect(subject.sensitive_url).to include 'signature=DIUgkQ_BaVBJU6hwhzH3GLeMdeo='
|
135
144
|
end
|
136
145
|
end
|
137
146
|
end
|
138
147
|
end
|
148
|
+
|
149
|
+
describe '#filtered_url' do
|
150
|
+
it 'filters nothing if config has no keys to be filtered' do
|
151
|
+
config.filter_parameters_in_logged_url.clear
|
152
|
+
|
153
|
+
expect(subject)
|
154
|
+
.to receive(:sensitive_url)
|
155
|
+
.and_return 'https://example.com/?foo=bar&sensitive=secret'
|
156
|
+
|
157
|
+
expect(subject.filtered_url).to eq 'https://example.com/?foo=bar&sensitive=secret'
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'filters sensitive GET param if config has it in list of params to filter' do
|
161
|
+
config.filter_parameters_in_logged_url << 'sensitive'
|
162
|
+
|
163
|
+
expect(subject)
|
164
|
+
.to receive(:sensitive_url)
|
165
|
+
.and_return 'https://example.com/?foo=bar&sensitive=secret'
|
166
|
+
|
167
|
+
expect(subject.filtered_url).to eq 'https://example.com/?foo=bar&sensitive=[FILTERED]'
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'filters key and signature as defaul from configuration' do
|
171
|
+
expect(subject)
|
172
|
+
.to receive(:sensitive_url)
|
173
|
+
.and_return 'https://example.com/?key=bar&signature=secret&other=foo'
|
174
|
+
|
175
|
+
expect(subject.filtered_url)
|
176
|
+
.to eq 'https://example.com/?key=[FILTERED]&signature=[FILTERED]&other=foo'
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'filters all appearances of a param' do
|
180
|
+
expect(subject)
|
181
|
+
.to receive(:sensitive_url)
|
182
|
+
.and_return 'https://example.com/?key=bar&key=secret&other=foo'
|
183
|
+
|
184
|
+
expect(subject.filtered_url)
|
185
|
+
.to eq 'https://example.com/?key=[FILTERED]&key=[FILTERED]&other=foo'
|
186
|
+
end
|
187
|
+
end
|
139
188
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'google_distance_matrix'
|
3
5
|
|
@@ -15,7 +17,7 @@ module RecordedRequestHelpers
|
|
15
17
|
private
|
16
18
|
|
17
19
|
def path_to(name)
|
18
|
-
File.join File.dirname(__FILE__),
|
20
|
+
File.join File.dirname(__FILE__), 'request_recordings', name.to_s
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_distance_matrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorbjørn Hermansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.13
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 3.2.13
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activemodel
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,6 +37,9 @@ dependencies:
|
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: 3.2.13
|
40
|
+
- - "<="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '5'
|
34
43
|
type: :runtime
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +47,9 @@ dependencies:
|
|
38
47
|
- - ">="
|
39
48
|
- !ruby/object:Gem::Version
|
40
49
|
version: 3.2.13
|
50
|
+
- - "<="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '5'
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: google_business_api_url_signer
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +84,28 @@ dependencies:
|
|
72
84
|
requirements:
|
73
85
|
- - "~>"
|
74
86
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
87
|
+
version: 3.5.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 3.5.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubocop
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.48'
|
76
102
|
type: :development
|
77
103
|
prerelease: false
|
78
104
|
version_requirements: !ruby/object:Gem::Requirement
|
79
105
|
requirements:
|
80
106
|
- - "~>"
|
81
107
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
108
|
+
version: '0.48'
|
83
109
|
- !ruby/object:Gem::Dependency
|
84
110
|
name: shoulda-matchers
|
85
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +126,14 @@ dependencies:
|
|
100
126
|
requirements:
|
101
127
|
- - "~>"
|
102
128
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
129
|
+
version: 3.0.1
|
104
130
|
type: :development
|
105
131
|
prerelease: false
|
106
132
|
version_requirements: !ruby/object:Gem::Requirement
|
107
133
|
requirements:
|
108
134
|
- - "~>"
|
109
135
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
136
|
+
version: 3.0.1
|
111
137
|
- !ruby/object:Gem::Dependency
|
112
138
|
name: rake
|
113
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +155,9 @@ executables: []
|
|
129
155
|
extensions: []
|
130
156
|
extra_rdoc_files: []
|
131
157
|
files:
|
158
|
+
- ".editorconfig"
|
132
159
|
- ".gitignore"
|
160
|
+
- ".rubocop.yml"
|
133
161
|
- ".ruby-version"
|
134
162
|
- ".travis.yml"
|
135
163
|
- CHANGELOG.md
|
@@ -194,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
222
|
version: '0'
|
195
223
|
requirements: []
|
196
224
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.5.
|
225
|
+
rubygems_version: 2.5.2
|
198
226
|
signing_key:
|
199
227
|
specification_version: 4
|
200
228
|
summary: Ruby client for The Google Distance Matrix API
|