googlemaps-services 1.4.8 → 1.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/lib/googlemaps/services/client.rb +25 -17
- data/lib/googlemaps/services/directions.rb +6 -2
- data/lib/googlemaps/services/distancematrix.rb +7 -3
- data/lib/googlemaps/services/elevation.rb +7 -3
- data/lib/googlemaps/services/exceptions.rb +6 -0
- data/lib/googlemaps/services/geocoding.rb +12 -4
- data/lib/googlemaps/services/geolocation.rb +7 -5
- data/lib/googlemaps/services/places.rb +41 -19
- data/lib/googlemaps/services/roads.rb +17 -10
- data/lib/googlemaps/services/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d66db18e76aaabbfda292e570796a06925b53d2c
|
4
|
+
data.tar.gz: 791a850530ab52c1cb6e886ee58f1658c5661773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d9c0b8161bf737619fb1b463c52176087ae74d9c064bdc742a732266edc5ce90149406e3d4a2c2601b25a0a5d2e6c33a47535fd726348d1d2a1cd5bd5d97ef
|
7
|
+
data.tar.gz: 4169f501b2e62b6ad6729ef13f53c42aeb8ca008f32e1633d05e027e35c3bf9bfdbc5c2542c8f92d6535fe93973affa5a065c9c8ed0e27fac27ad51394f45898
|
@@ -38,16 +38,18 @@ module GoogleMaps
|
|
38
38
|
attr_accessor :retry_timeout
|
39
39
|
# @return [Symbol] HTTP headers per request.
|
40
40
|
attr_accessor :request_headers
|
41
|
-
# @return [Symbol]
|
41
|
+
# @return [Symbol] Number of queries per second permitted. If the rate limit is reached, the client will sleep for the appropriate amount of time before it runs the current query.
|
42
42
|
attr_accessor :queries_per_second
|
43
43
|
# @return [Symbol] keeps track of sent queries.
|
44
44
|
attr_accessor :sent_times
|
45
|
+
# @return [Symbol] Should retry request when exceeds the query rate limit.
|
46
|
+
attr_accessor :retry_over_query_limit
|
45
47
|
# @return [Symbol] Response format. Either :json or :xml
|
46
48
|
attr_accessor :response_format
|
47
49
|
|
48
50
|
def initialize(key: nil, client_id: nil, client_secret: nil, write_timeout: 2,
|
49
51
|
connect_timeout: 5, read_timeout: 10, retry_timeout: 60, request_headers: {},
|
50
|
-
queries_per_second:
|
52
|
+
queries_per_second: 50, channel: nil, retry_over_query_limit: true, response_format: :json)
|
51
53
|
unless key || (client_secret && client_id)
|
52
54
|
raise StandardError, 'Must provide API key or enterprise credentials when creating client.'
|
53
55
|
end
|
@@ -75,9 +77,10 @@ module GoogleMaps
|
|
75
77
|
self.client_secret = client_secret
|
76
78
|
self.channel = channel
|
77
79
|
self.retry_timeout = retry_timeout
|
78
|
-
self.request_headers = request_headers.merge({
|
80
|
+
self.request_headers = request_headers.merge({'User-Agent' => Constants::USER_AGENT})
|
79
81
|
self.queries_per_second = queries_per_second
|
80
82
|
self.sent_times = Array.new
|
83
|
+
self.retry_over_query_limit = retry_over_query_limit
|
81
84
|
|
82
85
|
if response_format
|
83
86
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.' unless [:json, :xml].include? response_format
|
@@ -100,7 +103,7 @@ module GoogleMaps
|
|
100
103
|
#
|
101
104
|
# @return [Hash, Array, nil] response body (either in JSON or XML) or nil.
|
102
105
|
def request(url:, params:, first_request_time: nil, retry_counter: 0, base_url: Constants::DEFAULT_BASE_URL,
|
103
|
-
|
106
|
+
accepts_clientid: true, extract_body: nil, request_headers: nil, post_json: nil)
|
104
107
|
first_request_time = Util.current_time unless first_request_time
|
105
108
|
|
106
109
|
elapsed = Time.now - first_request_time
|
@@ -128,15 +131,16 @@ module GoogleMaps
|
|
128
131
|
|
129
132
|
# Create the request, add the headers & timeouts
|
130
133
|
req = HTTP.headers(request_headers)
|
131
|
-
|
134
|
+
.timeout(:write => self.write_timeout, :connect => self.connect_timeout, :read => self.read_timeout)
|
132
135
|
|
133
136
|
# Make the HTTP GET/POST request
|
134
137
|
resp = post_json ? req.post(uri.to_s, :json => post_json) : req.get(uri.to_s)
|
135
138
|
|
136
139
|
if Constants::RETRIABLE_STATUSES.include? resp.code.to_i
|
137
140
|
# Retry request
|
138
|
-
self.request(url: url, params: params, first_request_time: first_request_time, retry_counter: retry_counter + 1,
|
139
|
-
|
141
|
+
self.request(url: url, params: params, first_request_time: first_request_time, retry_counter: retry_counter + 1,
|
142
|
+
base_url: base_url, accepts_clientid: accepts_clientid, extract_body: extract_body,
|
143
|
+
request_headers: request_headers, post_json: post_json)
|
140
144
|
end
|
141
145
|
|
142
146
|
# Check if the time of the nth previous query (where n is queries_per_second)
|
@@ -166,10 +170,14 @@ module GoogleMaps
|
|
166
170
|
end
|
167
171
|
self.sent_times.push(Util.current_time)
|
168
172
|
return result
|
169
|
-
rescue RetriableRequest
|
173
|
+
rescue RetriableRequest => e
|
174
|
+
if e.is_a?(OverQueryLimit) && !self.retry_over_query_limit
|
175
|
+
raise
|
176
|
+
end
|
170
177
|
# Retry request
|
171
|
-
self.request(url: url, params: params, first_request_time: first_request_time, retry_counter: retry_counter + 1,
|
172
|
-
|
178
|
+
self.request(url: url, params: params, first_request_time: first_request_time, retry_counter: retry_counter + 1,
|
179
|
+
base_url: base_url, accepts_clientid: accepts_clientid, extract_body: extract_body,
|
180
|
+
request_headers: request_headers, post_json: post_json)
|
173
181
|
end
|
174
182
|
end
|
175
183
|
|
@@ -212,7 +220,7 @@ module GoogleMaps
|
|
212
220
|
end
|
213
221
|
|
214
222
|
if api_status == 'OVER_QUERY_LIMIT'
|
215
|
-
raise
|
223
|
+
raise OverQueryLimit
|
216
224
|
end
|
217
225
|
|
218
226
|
if body.key?('error_message')
|
@@ -236,7 +244,7 @@ module GoogleMaps
|
|
236
244
|
|
237
245
|
# Parse the XML response body
|
238
246
|
begin
|
239
|
-
doc = Nokogiri::XML(resp.body) {
|
247
|
+
doc = Nokogiri::XML(resp.body) {|config| config.strict}
|
240
248
|
rescue
|
241
249
|
raise APIError.new(status_code), 'Received a malformed XML response.'
|
242
250
|
end
|
@@ -247,7 +255,7 @@ module GoogleMaps
|
|
247
255
|
end
|
248
256
|
|
249
257
|
if api_status == 'OVER_QUERY_LIMIT'
|
250
|
-
raise
|
258
|
+
raise OverQueryLimit
|
251
259
|
end
|
252
260
|
|
253
261
|
error_message = doc.xpath('//error_message')
|
@@ -271,9 +279,9 @@ module GoogleMaps
|
|
271
279
|
end
|
272
280
|
|
273
281
|
{
|
274
|
-
|
275
|
-
|
276
|
-
|
282
|
+
:url => resp.uri.to_s,
|
283
|
+
:mime_type => resp.content_type.mime_type,
|
284
|
+
:image_data => Base64.encode64(resp.body).gsub(/\n/, '')
|
277
285
|
}
|
278
286
|
end
|
279
287
|
|
@@ -286,7 +294,7 @@ module GoogleMaps
|
|
286
294
|
# @param [TrueClass, FalseClass] accepts_clientid Flag whether to use a Client ID or not.
|
287
295
|
#
|
288
296
|
# @return [String] the final request path.
|
289
|
-
def generate_auth_url(path, params={}, accepts_clientid)
|
297
|
+
def generate_auth_url(path, params = {}, accepts_clientid)
|
290
298
|
if accepts_clientid && self.client_id && self.client_secret
|
291
299
|
if self.channel
|
292
300
|
params['channel'] = self.channel
|
@@ -116,9 +116,13 @@ module GoogleMaps
|
|
116
116
|
|
117
117
|
case self.client.response_format
|
118
118
|
when :xml
|
119
|
-
self.client
|
119
|
+
self.client
|
120
|
+
.request(url: '/maps/api/directions/xml', params: params)
|
121
|
+
.xpath('//route')
|
120
122
|
when :json
|
121
|
-
self.client
|
123
|
+
self.client
|
124
|
+
.request(url: '/maps/api/directions/json', params: params)
|
125
|
+
.fetch('routes', [])
|
122
126
|
else
|
123
127
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.'
|
124
128
|
end
|
@@ -34,11 +34,11 @@ module GoogleMaps
|
|
34
34
|
# @param [String] transit_routing_preference Specifies preferences for transit requests. Valid values are "less_walking" or "fewer_transfers".
|
35
35
|
# @param [String] traffic_model Specifies the predictive travel time model to use. Valid values are "best_guess" or "optimistic" or "pessimistic".
|
36
36
|
# The traffic_model parameter may only be specified for requests where the travel mode is driving, and where the request includes a departure_time.
|
37
|
+
# @param [String] region The region code, specified as a ccTLD (country code top-level domain) two-character value.
|
37
38
|
#
|
38
39
|
# @return [Hash, Nokogiri::XML::Document] Matrix of distances.
|
39
|
-
def query(origins:, destinations:, mode: nil, language: nil, avoid: nil,
|
40
|
-
|
41
|
-
transit_routing_preference: nil, traffic_model: nil)
|
40
|
+
def query(origins:, destinations:, mode: nil, language: nil, avoid: nil, units: nil, departure_time: nil,
|
41
|
+
arrival_time: nil, transit_mode: nil, transit_routing_preference: nil, traffic_model: nil, region: nil)
|
42
42
|
params = {
|
43
43
|
'origins' => Convert.piped_location(origins),
|
44
44
|
'destinations' => Convert.piped_location(destinations)
|
@@ -86,6 +86,10 @@ module GoogleMaps
|
|
86
86
|
params['traffic_model'] = traffic_model
|
87
87
|
end
|
88
88
|
|
89
|
+
if region
|
90
|
+
params['region'] = region
|
91
|
+
end
|
92
|
+
|
89
93
|
self.client.request(url: "/maps/api/distancematrix/#{self.client.response_format}", params: params)
|
90
94
|
end
|
91
95
|
end
|
@@ -42,7 +42,7 @@ module GoogleMaps
|
|
42
42
|
raise TypeError, 'Path should be either a String or an Array.'
|
43
43
|
end
|
44
44
|
|
45
|
-
params = {'path' => path, 'samples' => samples
|
45
|
+
params = {'path' => path, 'samples' => samples}
|
46
46
|
end
|
47
47
|
|
48
48
|
if path && locations
|
@@ -51,9 +51,13 @@ module GoogleMaps
|
|
51
51
|
|
52
52
|
case self.client.response_format
|
53
53
|
when :xml
|
54
|
-
self.client
|
54
|
+
self.client
|
55
|
+
.request(url: '/maps/api/elevation/xml', params: params)
|
56
|
+
.xpath('//result')
|
55
57
|
when :json
|
56
|
-
self.client
|
58
|
+
self.client
|
59
|
+
.request(url: '/maps/api/elevation/json', params: params)
|
60
|
+
.fetch('results', [])
|
57
61
|
else
|
58
62
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.'
|
59
63
|
end
|
@@ -50,6 +50,12 @@ module GoogleMaps
|
|
50
50
|
class RetriableRequest < Exception
|
51
51
|
end
|
52
52
|
|
53
|
+
# Signifies that the request failed because the client exceeded its query rate limit.
|
54
|
+
# Normally we treat this as a retriable condition, but we allow the calling code to specify
|
55
|
+
# that these requests should not be retried.
|
56
|
+
class OverQueryLimit < RetriableRequest
|
57
|
+
end
|
58
|
+
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
@@ -55,9 +55,13 @@ module GoogleMaps
|
|
55
55
|
|
56
56
|
case self.client.response_format
|
57
57
|
when :xml
|
58
|
-
self.client
|
58
|
+
self.client
|
59
|
+
.request(url: '/maps/api/geocode/xml', params: params)
|
60
|
+
.xpath('//result')
|
59
61
|
when :json
|
60
|
-
self.client
|
62
|
+
self.client
|
63
|
+
.request(url: '/maps/api/geocode/json', params: params)
|
64
|
+
.fetch('results', [])
|
61
65
|
else
|
62
66
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.'
|
63
67
|
end
|
@@ -107,9 +111,13 @@ module GoogleMaps
|
|
107
111
|
|
108
112
|
case self.client.response_format
|
109
113
|
when :xml
|
110
|
-
self.client
|
114
|
+
self.client
|
115
|
+
.request(url: '/maps/api/geocode/xml', params: params)
|
116
|
+
.xpath('//result')
|
111
117
|
when :json
|
112
|
-
self.client
|
118
|
+
self.client
|
119
|
+
.request(url: '/maps/api/geocode/json', params: params)
|
120
|
+
.fetch('results', [])
|
113
121
|
else
|
114
122
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.'
|
115
123
|
end
|
@@ -94,6 +94,12 @@ module GoogleMaps
|
|
94
94
|
status_code = response.code.to_i
|
95
95
|
begin
|
96
96
|
body = JSON.parse(response.body)
|
97
|
+
if [200, 404].include? status_code
|
98
|
+
return body
|
99
|
+
end
|
100
|
+
if status_code == 403
|
101
|
+
raise OverQueryLimit
|
102
|
+
end
|
97
103
|
rescue JSON::ParserError
|
98
104
|
raise APIError.new(status_code), 'Received malformed response.'
|
99
105
|
end
|
@@ -101,11 +107,7 @@ module GoogleMaps
|
|
101
107
|
if body.key?('error')
|
102
108
|
raise APIError.new(status_code), body['error']['errors'][0]['reason']
|
103
109
|
end
|
104
|
-
|
105
|
-
if status_code != 200
|
106
|
-
raise HTTPError.new(status_code)
|
107
|
-
end
|
108
|
-
body
|
110
|
+
raise HTTPError.new(status_code)
|
109
111
|
end
|
110
112
|
|
111
113
|
private :_geolocation_extract
|
@@ -22,14 +22,15 @@ module GoogleMaps
|
|
22
22
|
# @param [Integer] max_price Restricts results to only those places with no greater than this price level. Valid values are in the range from 0 (most affordable) to 4 (most expensive).
|
23
23
|
# @param [TrueClass, FalseClass] open_now Return only those places that are open for business at the time the query is sent.
|
24
24
|
# @param [String] type Restricts the results to places matching the specified type. The full list of supported types is available here: https://developers.google.com/places/supported_types
|
25
|
+
# @param [String] region The region code, specified as a ccTLD (country code top-level domain) two-character value.
|
25
26
|
# @param [String] page_token Token from a previous search that when provided will returns the next page of results for the same search.
|
26
27
|
#
|
27
28
|
# @return [Hash, Nokogiri::XML::Document] Valid JSON or XML response.
|
28
29
|
def search(query:, location: nil, radius: nil, language: nil, min_price: nil,
|
29
|
-
max_price: nil, open_now: false, type: nil, page_token: nil)
|
30
|
+
max_price: nil, open_now: false, type: nil, region: nil, page_token: nil)
|
30
31
|
_places(url_part: 'text', query: query, location: location, radius: radius,
|
31
32
|
language: language, min_price: min_price, max_price: max_price,
|
32
|
-
open_now: open_now, type: type, page_token: page_token)
|
33
|
+
open_now: open_now, type: type, region: region, page_token: page_token)
|
33
34
|
end
|
34
35
|
|
35
36
|
# Performs nearby search for places.
|
@@ -47,8 +48,11 @@ module GoogleMaps
|
|
47
48
|
# @param [String] page_token Token from a previous search that when provided will returns the next page of results for the same search.
|
48
49
|
#
|
49
50
|
# @return [Hash, Nokogiri::XML::Document] Valid JSON or XML response.
|
50
|
-
def nearby(location
|
51
|
+
def nearby(location: nil, radius: nil, keyword: nil, language: nil, min_price: nil,
|
51
52
|
max_price: nil, name: nil, open_now: false, rank_by: nil, type: nil, page_token: nil)
|
53
|
+
if !location && !page_token
|
54
|
+
raise StandardError, 'either a location or page_token is required.'
|
55
|
+
end
|
52
56
|
if rank_by == 'distance'
|
53
57
|
if !(keyword || name || type)
|
54
58
|
raise StandardError, 'either a keyword, name or type arg is required when rank_by is set to distance.'
|
@@ -75,7 +79,8 @@ module GoogleMaps
|
|
75
79
|
#
|
76
80
|
# @return [Hash, Nokogiri::XML::Document] Valid JSON or XML response.
|
77
81
|
def radar(location:, radius:, keyword: nil, min_price: nil,
|
78
|
-
|
82
|
+
max_price: nil, name: nil, open_now: false, type: nil)
|
83
|
+
warn '[DEPRECATION] Places Radar is deprecated as of June 30, 2018. After that time, this feature will no longer be available.'
|
79
84
|
raise StandardError, 'either a keyword, name, or type arg is required.' unless (keyword || name || type)
|
80
85
|
|
81
86
|
_places(url_part: 'radar', location: location, radius: radius,
|
@@ -87,8 +92,8 @@ module GoogleMaps
|
|
87
92
|
# @private
|
88
93
|
def _places(url_part:, query: nil, location: nil, radius: nil, keyword: nil, language: nil,
|
89
94
|
min_price: 0, max_price: 4, name: nil, open_now: false, rank_by: nil, type: nil,
|
90
|
-
page_token: nil)
|
91
|
-
params = {'minprice' => min_price, 'maxprice' => max_price
|
95
|
+
region: nil, page_token: nil)
|
96
|
+
params = {'minprice' => min_price, 'maxprice' => max_price}
|
92
97
|
|
93
98
|
if query
|
94
99
|
params['query'] = query
|
@@ -126,6 +131,10 @@ module GoogleMaps
|
|
126
131
|
params['type'] = type
|
127
132
|
end
|
128
133
|
|
134
|
+
if region
|
135
|
+
params['region'] = region
|
136
|
+
end
|
137
|
+
|
129
138
|
if page_token
|
130
139
|
params['pagetoken'] = page_token
|
131
140
|
end
|
@@ -140,7 +149,7 @@ module GoogleMaps
|
|
140
149
|
#
|
141
150
|
# @return [Hash, Nokogiri::XML::Document] Valid JSON or XML response.
|
142
151
|
def place_details(place_id:, language: nil)
|
143
|
-
params = {'placeid' => place_id
|
152
|
+
params = {'placeid' => place_id}
|
144
153
|
if language
|
145
154
|
params['language'] = language
|
146
155
|
end
|
@@ -178,13 +187,15 @@ module GoogleMaps
|
|
178
187
|
# @param [String, Hash] location The latitude/longitude value for which you wish to obtain the closest, human-readable address.
|
179
188
|
# @param [Integer] radius Distance in meters within which to bias results.
|
180
189
|
# @param [String] language The language in which to return results.
|
181
|
-
# @param [String]
|
182
|
-
# @param [Hash] components A
|
190
|
+
# @param [String] types Restricts the results to places matching the specified type. The full list of supported types is available here: https://developers.google.com/places/web-service/autocomplete#place_types
|
191
|
+
# @param [Hash] components A grouping of places to which you would like to restrict your results. Currently, you can use components to filter by up to 5 countries for example: {'country': ['US', 'AU']}
|
192
|
+
# @param [TrueClass,FalseClass] strict_bounds Returns only those places that are strictly within the region defined by location and radius.
|
183
193
|
#
|
184
194
|
# @return [Array, Nokogiri::XML::NodeSet] Array of predictions.
|
185
|
-
def autocomplete(input_text:, offset: nil, location: nil, radius: nil, language: nil,
|
186
|
-
|
187
|
-
|
195
|
+
def autocomplete(input_text:, offset: nil, location: nil, radius: nil, language: nil,
|
196
|
+
types: nil, components: nil, strict_bounds: false)
|
197
|
+
_autocomplete(url_part: "", input_text: input_text, offset: offset, location: location, radius: radius,
|
198
|
+
language: language, types: types, components: components, strict_bounds: strict_bounds)
|
188
199
|
end
|
189
200
|
|
190
201
|
# Returns Place predictions given a textual search query, such as "pizza near Brussels", and optional geographic bounds.
|
@@ -203,9 +214,9 @@ module GoogleMaps
|
|
203
214
|
|
204
215
|
# Handler for "autocomplete" and "autocomplete_query" queries.
|
205
216
|
# @private
|
206
|
-
def _autocomplete(url_part:, input_text:, offset: nil, location: nil,
|
207
|
-
|
208
|
-
params = {'input' => input_text
|
217
|
+
def _autocomplete(url_part:, input_text:, offset: nil, location: nil, radius: nil,
|
218
|
+
language: nil, types: nil, components: nil, strict_bounds: false)
|
219
|
+
params = {'input' => input_text}
|
209
220
|
|
210
221
|
if offset
|
211
222
|
params['offset'] = offset
|
@@ -223,19 +234,30 @@ module GoogleMaps
|
|
223
234
|
params['language'] = language
|
224
235
|
end
|
225
236
|
|
226
|
-
if
|
227
|
-
params['
|
237
|
+
if types
|
238
|
+
params['types'] = types
|
228
239
|
end
|
229
240
|
|
230
241
|
if components
|
242
|
+
if components.size != 1 || components.keys[0] != 'country'
|
243
|
+
raise StandardError, 'Only country components are supported.'
|
244
|
+
end
|
231
245
|
params['components'] = Convert.components(components)
|
232
246
|
end
|
233
247
|
|
248
|
+
if strict_bounds
|
249
|
+
params['strictbounds'] = 'true'
|
250
|
+
end
|
251
|
+
|
234
252
|
case self.client.response_format
|
235
253
|
when :xml
|
236
|
-
self.client
|
254
|
+
self.client
|
255
|
+
.request(url: "/maps/api/place/#{url_part}autocomplete/xml", params: params)
|
256
|
+
.xpath('//prediction')
|
237
257
|
when :json
|
238
|
-
self.client
|
258
|
+
self.client
|
259
|
+
.request(url: "/maps/api/place/#{url_part}autocomplete/json", params: params)
|
260
|
+
.fetch('predictions', [])
|
239
261
|
else
|
240
262
|
raise StandardError, 'Unsupported response format. Should be either :json or :xml.'
|
241
263
|
end
|
@@ -28,14 +28,16 @@ module GoogleMaps
|
|
28
28
|
#
|
29
29
|
# @return [Array] Array of snapped points.
|
30
30
|
def snap_to_roads(path:, interpolate: false)
|
31
|
-
params = {'path' => Convert.piped_location(path)
|
31
|
+
params = {'path' => Convert.piped_location(path)}
|
32
32
|
|
33
33
|
if interpolate
|
34
34
|
params['interpolate'] = 'true'
|
35
35
|
end
|
36
36
|
|
37
|
-
self.client
|
38
|
-
|
37
|
+
self.client
|
38
|
+
.request(url: '/v1/snapToRoads', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false,
|
39
|
+
extract_body: lambda(&method(:_roads_extract)))
|
40
|
+
.fetch('snappedPoints', [])
|
39
41
|
end
|
40
42
|
|
41
43
|
# Returns the posted speed limit (in km/h) for given road segments.
|
@@ -49,8 +51,10 @@ module GoogleMaps
|
|
49
51
|
|
50
52
|
params = {'placeId' => place_ids}
|
51
53
|
|
52
|
-
self.client
|
53
|
-
|
54
|
+
self.client
|
55
|
+
.request(url: '/v1/speedLimits', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false,
|
56
|
+
extract_body: lambda(&method(:_roads_extract)))
|
57
|
+
.fetch('speedLimits', [])
|
54
58
|
end
|
55
59
|
|
56
60
|
# Returns the posted speed limit (in km/h) for given road segments.
|
@@ -62,8 +66,9 @@ module GoogleMaps
|
|
62
66
|
def snapped_speed_limits(path:)
|
63
67
|
params = {'path' => Convert.piped_location(path)}
|
64
68
|
|
65
|
-
self.client
|
66
|
-
|
69
|
+
self.client
|
70
|
+
.request(url: '/v1/speedLimits', params: params, base_url: Constants::ROADS_BASE_URL,
|
71
|
+
accepts_clientid: false, extract_body: lambda(&method(:_roads_extract)))
|
67
72
|
end
|
68
73
|
|
69
74
|
# Find the closest road segments for each point.
|
@@ -76,8 +81,10 @@ module GoogleMaps
|
|
76
81
|
def nearest_roads(points:)
|
77
82
|
params = {'points' => Convert.piped_location(points)}
|
78
83
|
|
79
|
-
self.client
|
80
|
-
|
84
|
+
self.client
|
85
|
+
.request(url: '/v1/nearestRoads', params: params, base_url: Constants::ROADS_BASE_URL, accepts_clientid: false,
|
86
|
+
extract_body: lambda(&method(:_roads_extract)))
|
87
|
+
.fetch('snappedPoints', [])
|
81
88
|
end
|
82
89
|
|
83
90
|
# Extracts result from the Roads API HTTP response.
|
@@ -100,7 +107,7 @@ module GoogleMaps
|
|
100
107
|
status = error['status']
|
101
108
|
|
102
109
|
if status == 'RESOURCE_EXHAUSTED'
|
103
|
-
raise
|
110
|
+
raise OverQueryLimit
|
104
111
|
end
|
105
112
|
|
106
113
|
if error.respond_to?(:key?) && error.key?('message')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googlemaps-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faissal Elamraoui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|