google_distance_matrix 0.5.0 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2a2232b164549acbd29af07935315c8859dc19c
4
- data.tar.gz: 3f29dc7ef98d87e913c1372fabd660766150dc8b
2
+ SHA256:
3
+ metadata.gz: ec09fa5221e72649dc748457361fd70b8411ef4aaaf149d89cd611fb8283a046
4
+ data.tar.gz: 835d472137fae8e86ecdfb91355519ad951ae2cad6f476ed810d06258f82fa89
5
5
  SHA512:
6
- metadata.gz: bead0dcdb680422cac5db6463af54580036dc6fae0f98373eec513e18a3a197ca7981d57db4ca64a27cc7461e675bd181b81a284b0cd98129e98fa916735be28
7
- data.tar.gz: 0d6d9b8a96282568c647293adab6c58e9eed438e36d1e42f1f4b473a6da59c7cb5014eebc5cc56b4326211e8faa68e292651940a5f1e1d2c30b9b82ba5435710
6
+ metadata.gz: 147599c8ebad87d56263e53740bff7e6ed8ff610c0cc484fc54e2eb0bae0871f9c36aee64e584fd7c9406af28aaa67c7de315095265dd4ae46a2713b3294a1fd
7
+ data.tar.gz: 6fc3c60083417ebc18a63a01553421c9f26a8d55dcc63a0d8cee03ce4278addf97e69cb04a638ecd376aab4d97ec4258ccd9a1757a3958c466e392bcbd053e0c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.4
1
+ 2.5.5
data/.travis.yml CHANGED
@@ -1,13 +1,11 @@
1
1
  before_install:
2
2
  - gem update bundler
3
3
  rvm:
4
- - 2.1.0
5
- - 2.1.2
6
- - 2.1.5
7
- - 2.2.3
8
- - 2.3.0
9
- - 2.3.1
10
- - 2.3.4
4
+ - 3.0.1
5
+ - 2.6.2
6
+ - 2.5.5
7
+ - 2.4.5
8
+ - 2.3.8
11
9
  - ruby-head
12
10
  matrix:
13
11
  allow_failures:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## v.0.6.4
2
+
3
+ * fix: no longer throwing "Wrong number of arguments" when using the cache (by brianlow)
4
+
5
+ ## v.0.6.3
6
+
7
+ * chore: bumped dependency support up to Rails 6.1 (by mintyfresh)
8
+
9
+ ## v.0.6.2
10
+
11
+ * chore: bumped dependency support up to Rails 6 (by zackchandler)
12
+
13
+ ## v.0.6.1
14
+
15
+ * fix: when matrix places were built from hashes, passing hashes to route/s_for doesnt't work (by brauliomartinezlm)
16
+ * fix: place comparison was not working with == (by brauliomartinezlm)
17
+
18
+ ## v.0.6.0
19
+
20
+ * Depend on activemodel & activesupport < 5.3 (by brauliomartinezlm)
21
+ * Tested with Ruby 2.5.
22
+ * Dropped support for Ruby 2.2 and below.
23
+ * Added support for `channel` (by michaelgpearce)
24
+
1
25
  ## v.0.5.0
2
26
 
3
27
  This release contains breaking change where `url` has been renamed to
data/README.md CHANGED
@@ -11,9 +11,6 @@ pull the distance matrix from Google.
11
11
  Once you have the matrix you can fetch all routes from a given
12
12
  origin or to a given destination.
13
13
 
14
- The matrix may also be used as a data set for traveling salesman problem,
15
- but to solve it you may look at <http://ai4r.org/>.
16
-
17
14
 
18
15
 
19
16
 
@@ -1,6 +1,6 @@
1
1
  # frozen_String_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'google_distance_matrix/version'
6
6
 
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'activesupport', '>= 3.2.13', '<= 5'
23
- spec.add_dependency 'activemodel', '>= 3.2.13', '<= 5'
22
+ spec.add_dependency 'activemodel', '>= 3.2.13', '< 6.2'
23
+ spec.add_dependency 'activesupport', '>= 3.2.13', '< 6.2'
24
24
  spec.add_dependency 'google_business_api_url_signer', '~> 0.1.3'
25
25
 
26
26
  spec.add_development_dependency 'bundler'
27
- spec.add_development_dependency 'rspec', '~> 3.5.0'
28
- spec.add_development_dependency 'rubocop', '~> 0.48'
29
- spec.add_development_dependency 'shoulda-matchers', '~> 3.1.1'
30
- spec.add_development_dependency 'webmock', '~> 3.0.1'
31
27
  spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec', '~> 3.8.0'
29
+ spec.add_development_dependency 'rubocop', '~> 0.59.2'
30
+ spec.add_development_dependency 'shoulda-matchers', '~> 4.0.0.rc1'
31
+ spec.add_development_dependency 'webmock', '~> 3.4.2'
32
32
  end
@@ -19,7 +19,7 @@ module GoogleDistanceMatrix
19
19
 
20
20
  def get(url, options = {})
21
21
  cache.fetch self.class.key(url, options.fetch(:configuration)) do
22
- client.get url, options
22
+ client.get url, **options
23
23
  end
24
24
  end
25
25
  end
@@ -18,7 +18,7 @@ module GoogleDistanceMatrix
18
18
  mode avoid units language
19
19
  departure_time arrival_time
20
20
  transit_mode transit_routing_preference
21
- traffic_model
21
+ traffic_model channel
22
22
  ].freeze
23
23
 
24
24
  API_DEFAULTS = {
@@ -84,7 +84,7 @@ module GoogleDistanceMatrix
84
84
  API_DEFAULTS.each_pair do |attr_name, value|
85
85
  self[attr_name] = begin
86
86
  value.dup
87
- rescue
87
+ rescue StandardError
88
88
  value
89
89
  end
90
90
  end
@@ -105,10 +105,7 @@ module GoogleDistanceMatrix
105
105
  attr_and_value[1].nil? || param_same_as_api_default?(attr_and_value)
106
106
  end
107
107
 
108
- if google_business_api_client_id.present?
109
- out << ['client', google_business_api_client_id]
110
- end
111
-
108
+ out << ['client', google_business_api_client_id] if google_business_api_client_id.present?
112
109
  out << ['key', google_api_key] if google_api_key.present?
113
110
 
114
111
  out
@@ -19,7 +19,7 @@ module GoogleDistanceMatrix
19
19
  msg = args.first
20
20
  tags = PREFIXES.dup.concat Array.wrap(options[:tag])
21
21
 
22
- backend.public_send level, tag_msg(msg, tags) if backend
22
+ backend&.public_send level, tag_msg(msg, tags)
23
23
  end
24
24
  end
25
25
 
@@ -22,6 +22,7 @@ module GoogleDistanceMatrix
22
22
  if respond_to_needed_attributes? attributes_or_object
23
23
  extract_and_assign_attributes_from_object attributes_or_object
24
24
  elsif attributes_or_object.is_a? Hash
25
+ @extracted_attributes_from = attributes_or_object.with_indifferent_access
25
26
  assign_attributes attributes_or_object
26
27
  else
27
28
  raise ArgumentError, 'Must be either hash or object responding to lat, lng or address. '
@@ -36,12 +37,15 @@ module GoogleDistanceMatrix
36
37
  end
37
38
 
38
39
  def eql?(other)
40
+ return false unless other.is_a? self.class
41
+
39
42
  if address.present?
40
43
  address == other.address
41
44
  else
42
45
  lat_lng == other.lat_lng
43
46
  end
44
47
  end
48
+ alias == eql?
45
49
 
46
50
  def lat_lng?
47
51
  lat.present? && lng.present?
@@ -74,9 +78,7 @@ module GoogleDistanceMatrix
74
78
 
75
79
  def extract_and_assign_attributes_from_object(object)
76
80
  attrs = Hash[ATTRIBUTES.map do |attr_name|
77
- if object.respond_to? attr_name
78
- [attr_name, object.public_send(attr_name)]
79
- end
81
+ [attr_name, object.public_send(attr_name)] if object.respond_to? attr_name
80
82
  end.compact]
81
83
 
82
84
  attrs.delete 'address' if attrs.key?('lat') || attrs.key?('lng')
@@ -58,11 +58,12 @@ module GoogleDistanceMatrix
58
58
  #
59
59
  # Example of usage
60
60
  # p d 17998321 # => "00000001 00010010 10100001 11110001"
61
- def d(v, bits = 32, chunk_size = 8)
61
+ def d(val, bits = 32, chunk_size = 8)
62
62
  (bits - 1).downto(0)
63
- .map { |n| v[n] }
63
+ .map { |n| val[n] }
64
64
  .each_slice(chunk_size).map(&:join).join ' '
65
65
  end
66
66
  end
67
67
  end
68
68
  end
69
+ # rubocop:enable Style/NumericPredicate
@@ -10,8 +10,9 @@ module GoogleDistanceMatrix
10
10
 
11
11
  def initialize(matrix)
12
12
  @matrix = matrix
13
- end # Public: Finds routes for given place.
13
+ end
14
14
 
15
+ # Public: Finds routes for given place.
15
16
  #
16
17
  # place - Either an origin or destination, or an object which you built the place from
17
18
  #
@@ -53,9 +54,7 @@ module GoogleDistanceMatrix
53
54
  origin = ensure_place options[:origin]
54
55
  destination = ensure_place options[:destination]
55
56
 
56
- if origin.nil? || destination.nil?
57
- raise ArgumentError, 'Must provide origin and destination'
58
- end
57
+ raise ArgumentError, 'Must provide origin and destination' if origin.nil? || destination.nil?
59
58
 
60
59
  routes_for(origin).detect { |route| route.destination == destination }
61
60
  end
@@ -143,6 +142,8 @@ module GoogleDistanceMatrix
143
142
  if object.is_a? Place
144
143
  object
145
144
  else
145
+ object = object.with_indifferent_access if object.is_a? Hash
146
+
146
147
  find_place_for_object(origins, object) ||
147
148
  find_place_for_object(destinations, object)
148
149
  end
@@ -196,4 +197,5 @@ module GoogleDistanceMatrix
196
197
  raise InvalidQuery, 'Matrix must be in mode driving and a departure_time must be set'
197
198
  end
198
199
  end
200
+ # rubocop:enable Metrics/ClassLength
199
201
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleDistanceMatrix
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.4'
5
5
  end
@@ -29,6 +29,7 @@ describe GoogleDistanceMatrix::ClientCache do
29
29
 
30
30
  expect(subject.get(url, options)).to eq 'cached-data'
31
31
  end
32
+ # rubocop:enable Metrics/LineLength
32
33
 
33
34
  it 'asks client when cache miss' do
34
35
  expect(client).to receive(:get).with(url, options).and_return 'api-data'
@@ -95,4 +95,12 @@ describe GoogleDistanceMatrix::Place do
95
95
  .to_not be_eql described_class.new(lat: lat, lng: lng + 1)
96
96
  end
97
97
  end
98
+
99
+ describe '#==' do
100
+ it 'is considered equal when places are compared with ==' do
101
+ expect(described_class.new(address: address) ==
102
+ GoogleDistanceMatrix::Place.new(address: address))
103
+ .to be_truthy
104
+ end
105
+ end
98
106
  end
@@ -3,7 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
6
- let(:origin_1) { GoogleDistanceMatrix::Place.new address: 'Karl Johans gate, Oslo' }
6
+ let(:origin_1_attributes) { { address: 'Karl Johans gate, Oslo' } }
7
+ let(:origin_1) { GoogleDistanceMatrix::Place.new origin_1_attributes }
7
8
  let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
8
9
 
9
10
  let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
@@ -70,6 +71,13 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
70
71
  expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
71
72
  end
72
73
 
74
+ it 'still returns routes for origin if it has same address but different object_id' do
75
+ routes = subject.routes_for GoogleDistanceMatrix::Place.new origin_1_attributes
76
+
77
+ expect(routes.length).to eq 2
78
+ expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
79
+ end
80
+
73
81
  it 'returns routes for given destination' do
74
82
  routes = subject.routes_for destination_2
75
83
 
@@ -83,6 +91,17 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
83
91
  expect(routes.length).to eq 2
84
92
  expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
85
93
  end
94
+
95
+ context 'place built from hash' do
96
+ let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
97
+
98
+ it 'returns routes for given hash a place was built from' do
99
+ routes = subject.routes_for destination_2_built_from
100
+
101
+ expect(routes.length).to eq 2
102
+ expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
103
+ end
104
+ end
86
105
  end
87
106
 
88
107
  describe '#routes_for!' do
@@ -104,6 +123,16 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
104
123
  expect(route.destination).to eq destination_2
105
124
  end
106
125
 
126
+ context 'place built from hash' do
127
+ let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
128
+
129
+ it 'returns route when you give it the hash the place was built from' do
130
+ route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
131
+ expect(route.origin).to eq origin_1
132
+ expect(route.destination).to eq destination_2
133
+ end
134
+ end
135
+
107
136
  it 'fails with argument error if origin is missing' do
108
137
  expect { subject.route_for destination: destination_2 }.to raise_error ArgumentError
109
138
  end
@@ -49,7 +49,7 @@ describe GoogleDistanceMatrix::UrlBuilder do
49
49
 
50
50
  describe '#sensitive_url' do
51
51
  it 'fails if the url is more than 2048 characters' do
52
- long_string = ''.dup
52
+ long_string = +''
53
53
  2049.times { long_string << 'a' }
54
54
 
55
55
  expect(subject).to receive(:query_params_string).and_return long_string
metadata CHANGED
@@ -1,25 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_distance_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.4
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: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.13
20
- - - "<="
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,19 +27,19 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.2.13
30
- - - "<="
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
- name: activemodel
34
+ name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 3.2.13
40
- - - "<="
40
+ - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5'
42
+ version: '6.2'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +47,9 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.2.13
50
- - - "<="
50
+ - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5'
52
+ version: '6.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: google_business_api_url_signer
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -79,75 +79,75 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: rspec
82
+ name: rake
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
- version: 3.5.0
87
+ version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - "~>"
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 3.5.0
94
+ version: '0'
95
95
  - !ruby/object:Gem::Dependency
96
- name: rubocop
96
+ name: rspec
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '0.48'
101
+ version: 3.8.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '0.48'
108
+ version: 3.8.0
109
109
  - !ruby/object:Gem::Dependency
110
- name: shoulda-matchers
110
+ name: rubocop
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: 3.1.1
115
+ version: 0.59.2
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 3.1.1
122
+ version: 0.59.2
123
123
  - !ruby/object:Gem::Dependency
124
- name: webmock
124
+ name: shoulda-matchers
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 3.0.1
129
+ version: 4.0.0.rc1
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: 3.0.1
136
+ version: 4.0.0.rc1
137
137
  - !ruby/object:Gem::Dependency
138
- name: rake
138
+ name: webmock
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ">="
141
+ - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '0'
143
+ version: 3.4.2
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - ">="
148
+ - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: 3.4.2
151
151
  description: Ruby client for The Google Distance Matrix API
152
152
  email:
153
153
  - thhermansen@gmail.com
@@ -221,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  requirements: []
224
- rubyforge_project:
225
- rubygems_version: 2.5.2
224
+ rubygems_version: 3.0.3
226
225
  signing_key:
227
226
  specification_version: 4
228
227
  summary: Ruby client for The Google Distance Matrix API