travel_time 0.5.1 → 0.5.5
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/README.md +113 -143
- data/lib/travel_time/client.rb +8 -12
- data/lib/travel_time/middleware/authentication.rb +1 -1
- data/lib/travel_time/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 980351a64bc02a09468036537289c94c69e92524ced3303539a4849254f1ad6b
|
4
|
+
data.tar.gz: 70232585d25f0a8dfa63b4f4b4a2fef827381e509ded12f3f641cfff58c88482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5c2aec26726acb47a74cfdd6608a0db0243fcfb7fa8c24ab4e86e9bf36bad03294b16bbeb8cbe6d1b1b671c801fb34227a140e1e6053b9612213e12e270d70
|
7
|
+
data.tar.gz: 8c43d33f903df991fa35162d170ef71fa9ebb44cf21dd1570e718ae8e6adf98bbf825117dc4235dc38b843a4956f664f62e42968f03fb98461082569af78336d
|
data/README.md
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
[](https://rubygems.org/gems/travel_time)
|
4
4
|
[](https://github.com/traveltime-dev/traveltime-sdk-ruby/actions?query=workflow%3ACI)
|
5
5
|
|
6
|
-
|
7
|
-
This open-source library allows you to access [TravelTime API](https://docs.traveltime.com/overview/introduction)
|
8
|
-
endpoints.
|
6
|
+
[Travel Time](https://docs.traveltime.com/api/overview/introduction) Ruby SDK helps users find locations by journey time rather than using ‘as the crow flies’ distance. Time-based searching gives users more opportunities for personalisation and delivers a more relevant search.
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -30,7 +28,7 @@ In order to be able to call the API, you'll first need to set your Application I
|
|
30
28
|
```ruby
|
31
29
|
TravelTime.configure do |config|
|
32
30
|
config.application_id = '<your app id>'
|
33
|
-
config.api_key = '<your
|
31
|
+
config.api_key = '<your app key>'
|
34
32
|
end
|
35
33
|
```
|
36
34
|
|
@@ -70,11 +68,16 @@ departure_search = {
|
|
70
68
|
client.time_map(departure_searches: [departure_search])
|
71
69
|
```
|
72
70
|
|
73
|
-
|
74
71
|
### [Isochrones (Time Map)](https://traveltime.com/docs/api/reference/isochrones)
|
75
72
|
Given origin coordinates, find shapes of zones reachable within corresponding travel time.
|
76
73
|
Find unions/intersections between different searches.
|
77
74
|
|
75
|
+
Body attributes:
|
76
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches.
|
77
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches.
|
78
|
+
* unions: Define unions of shapes that are results of previously defined searches.
|
79
|
+
* intersections: Define intersections of shapes that are results of previously defined searches.
|
80
|
+
|
78
81
|
```ruby
|
79
82
|
require 'time'
|
80
83
|
|
@@ -133,25 +136,14 @@ arrival_search = {
|
|
133
136
|
lng: -0.128050
|
134
137
|
},
|
135
138
|
transportation: { type: "public_transport" },
|
136
|
-
|
139
|
+
arrival_time_period: 'weekday_morning',
|
137
140
|
travel_time: 1800,
|
138
141
|
}
|
139
142
|
|
140
|
-
union = {
|
141
|
-
id: 'union of driving and public transport',
|
142
|
-
search_ids: ['public transport from Trafalgar Square', 'public transport to Trafalgar Square']
|
143
|
-
}
|
144
|
-
intersection = {
|
145
|
-
id: 'intersection of driving and public transport',
|
146
|
-
search_ids: ['public transport from Trafalgar Square', 'public transport to Trafalgar Square']
|
147
|
-
}
|
148
|
-
|
149
143
|
response = client.time_map_fast(
|
150
144
|
arrival_searches: {
|
151
145
|
one_to_many: [arrival_search]
|
152
|
-
},
|
153
|
-
unions: [union],
|
154
|
-
intersections: [intersection]
|
146
|
+
},
|
155
147
|
)
|
156
148
|
|
157
149
|
puts response.body
|
@@ -161,6 +153,11 @@ puts response.body
|
|
161
153
|
Given origin and destination points filter out points that cannot be reached within specified time limit.
|
162
154
|
Find out travel times, distances and costs between an origin and up to 2,000 destination points.
|
163
155
|
|
156
|
+
Body attributes:
|
157
|
+
* locations: Locations to use. Each location requires an id and lat/lng values
|
158
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches
|
159
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches
|
160
|
+
|
164
161
|
```ruby
|
165
162
|
require 'time'
|
166
163
|
|
@@ -218,74 +215,8 @@ response = client.time_filter(
|
|
218
215
|
puts response.body
|
219
216
|
```
|
220
217
|
|
221
|
-
### [Routes](https://traveltime.com/docs/api/reference/routes)
|
222
|
-
Returns routing information between source and destinations.
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
require 'time'
|
226
|
-
|
227
|
-
locations = [{
|
228
|
-
id: 'London center',
|
229
|
-
coords: {
|
230
|
-
lat: 51.508930,
|
231
|
-
lng: -0.131387
|
232
|
-
}
|
233
|
-
},
|
234
|
-
{
|
235
|
-
id: 'Hyde Park',
|
236
|
-
coords: {
|
237
|
-
lat: 51.508824,
|
238
|
-
lng: -0.167093
|
239
|
-
}
|
240
|
-
},
|
241
|
-
{
|
242
|
-
id: 'ZSL London Zoo',
|
243
|
-
coords: {
|
244
|
-
lat: 51.536067,
|
245
|
-
lng: -0.153596
|
246
|
-
}
|
247
|
-
}]
|
248
|
-
|
249
|
-
departure_search = {
|
250
|
-
id: 'forward search example',
|
251
|
-
departure_location_id: 'London center',
|
252
|
-
arrival_location_ids: ['Hyde Park', 'ZSL London Zoo'],
|
253
|
-
transportation: {
|
254
|
-
type: 'bus'
|
255
|
-
},
|
256
|
-
departure_time: Time.now.iso8601,
|
257
|
-
travel_time: 1800,
|
258
|
-
properties: ['travel_time'],
|
259
|
-
range: {
|
260
|
-
enabled: true,
|
261
|
-
max_results: 3,
|
262
|
-
width: 600
|
263
|
-
}
|
264
|
-
}
|
265
|
-
|
266
|
-
arrival_search = {
|
267
|
-
id: 'backward search example',
|
268
|
-
departure_location_ids: ['Hyde Park', 'ZSL London Zoo'],
|
269
|
-
arrival_location_id: 'London center',
|
270
|
-
transportation: {
|
271
|
-
type: 'public_transport'
|
272
|
-
},
|
273
|
-
arrival_time: Time.now.iso8601,
|
274
|
-
travel_time: 1800,
|
275
|
-
properties: ['travel_time', 'distance', 'fares', 'route']
|
276
|
-
}
|
277
|
-
|
278
|
-
response = client.routes(
|
279
|
-
locations: locations,
|
280
|
-
departure_searches: [departure_search],
|
281
|
-
arrival_searches: [arrival_search]
|
282
|
-
)
|
283
|
-
|
284
|
-
puts response.body
|
285
|
-
```
|
286
|
-
|
287
218
|
### [Time Filter (Fast)](https://traveltime.com/docs/api/reference/time-filter-fast)
|
288
|
-
A very fast version of time_filter()
|
219
|
+
A very fast version of `time_filter()`.
|
289
220
|
However, the request parameters are much more limited.
|
290
221
|
Currently only supports UK and Ireland.
|
291
222
|
|
@@ -347,7 +278,7 @@ response = client.time_filter_fast(
|
|
347
278
|
puts response.body
|
348
279
|
```
|
349
280
|
|
350
|
-
### [Time Filter
|
281
|
+
### [Time Filter Fast (Proto)](https://docs.traveltime.com/api/reference/travel-time-distance-matrix-proto)
|
351
282
|
A fast version of time filter communicating using [protocol buffers](https://github.com/protocolbuffers/protobuf).
|
352
283
|
|
353
284
|
The request parameters are much more limited and only travel time is returned. In addition, the results are only approximately correct (95% of the results are guaranteed to be within 5% of the routes returned by regular time filter).
|
@@ -357,9 +288,9 @@ This inflexibility comes with a benefit of faster response times (Over 5x faster
|
|
357
288
|
Body attributes:
|
358
289
|
* origin: Origin point.
|
359
290
|
* destinations: Destination points. Cannot be more than 200,000.
|
291
|
+
* country: Return the results that are within the specified country.
|
360
292
|
* transport: Transportation type.
|
361
|
-
*
|
362
|
-
* country: Return the results that are within the specified country
|
293
|
+
* traveltime: Time limit.
|
363
294
|
|
364
295
|
```ruby
|
365
296
|
origin = {
|
@@ -382,42 +313,97 @@ response = client.time_filter_fast_proto(
|
|
382
313
|
puts(response.body)
|
383
314
|
```
|
384
315
|
|
385
|
-
|
386
|
-
A version of `Time Filter (Fast) Proto` endpoint that also returns distance information. Request parameters are even more limited than `Time Filter (Fast) Proto`.
|
316
|
+
The responses are in the form of a list where each position denotes either a travel time (in seconds) of a journey, or if negative that the journey from the origin to the destination point is impossible.
|
387
317
|
|
388
|
-
|
318
|
+
### [Routes](https://traveltime.com/docs/api/reference/routes)
|
319
|
+
Returns routing information between source and destinations.
|
389
320
|
|
390
321
|
Body attributes:
|
391
|
-
*
|
392
|
-
*
|
393
|
-
*
|
394
|
-
* travelTime: Time limit;
|
395
|
-
* country: Return the results that are within the specified country
|
322
|
+
* locations: Locations to use. Each location requires an id and lat/lng values.
|
323
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches.
|
324
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches.
|
396
325
|
|
397
326
|
```ruby
|
398
|
-
|
399
|
-
lat: 51.508930,
|
400
|
-
lng: -0.131387,
|
401
|
-
}
|
327
|
+
require 'time'
|
402
328
|
|
403
|
-
|
404
|
-
|
405
|
-
|
329
|
+
locations = [{
|
330
|
+
id: 'London center',
|
331
|
+
coords: {
|
332
|
+
lat: 51.508930,
|
333
|
+
lng: -0.131387
|
334
|
+
}
|
335
|
+
},
|
336
|
+
{
|
337
|
+
id: 'Hyde Park',
|
338
|
+
coords: {
|
339
|
+
lat: 51.508824,
|
340
|
+
lng: -0.167093
|
341
|
+
}
|
342
|
+
},
|
343
|
+
{
|
344
|
+
id: 'ZSL London Zoo',
|
345
|
+
coords: {
|
346
|
+
lat: 51.536067,
|
347
|
+
lng: -0.153596
|
348
|
+
}
|
406
349
|
}]
|
407
350
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
351
|
+
departure_search = {
|
352
|
+
id: 'forward search example',
|
353
|
+
departure_location_id: 'London center',
|
354
|
+
arrival_location_ids: ['Hyde Park', 'ZSL London Zoo'],
|
355
|
+
transportation: {
|
356
|
+
type: 'bus'
|
357
|
+
},
|
358
|
+
departure_time: Time.now.iso8601,
|
359
|
+
travel_time: 1800,
|
360
|
+
properties: ['travel_time'],
|
361
|
+
range: {
|
362
|
+
enabled: true,
|
363
|
+
max_results: 3,
|
364
|
+
width: 600
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
arrival_search = {
|
369
|
+
id: 'backward search example',
|
370
|
+
departure_location_ids: ['Hyde Park', 'ZSL London Zoo'],
|
371
|
+
arrival_location_id: 'London center',
|
372
|
+
transportation: {
|
373
|
+
type: 'public_transport'
|
374
|
+
},
|
375
|
+
arrival_time: Time.now.iso8601,
|
376
|
+
travel_time: 1800,
|
377
|
+
properties: ['travel_time', 'distance', 'fares', 'route']
|
378
|
+
}
|
379
|
+
|
380
|
+
response = client.routes(
|
381
|
+
locations: locations,
|
382
|
+
departure_searches: [departure_search],
|
383
|
+
arrival_searches: [arrival_search]
|
414
384
|
)
|
415
|
-
|
385
|
+
|
386
|
+
puts response.body
|
416
387
|
```
|
417
388
|
|
389
|
+
### [Geocoding (Search)](https://traveltime.com/docs/api/reference/geocoding-search)
|
390
|
+
Match a query string to geographic coordinates.
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
response = client.geocoding(query: 'London', within_country: 'GB')
|
394
|
+
puts response.body
|
395
|
+
```
|
418
396
|
|
419
|
-
### [
|
420
|
-
|
397
|
+
### [Reverse Geocoding](https://traveltime.com/docs/api/reference/geocoding-reverse)
|
398
|
+
Attempt to match a latitude, longitude pair to an address.
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
response = client.reverse_geocoding(lat: 51.506756, lng: -0.128050)
|
402
|
+
puts response.body
|
403
|
+
```
|
404
|
+
|
405
|
+
### [Time Filter (Postcodes)](https://traveltime.com/docs/api/reference/postcode-search)
|
406
|
+
Find reachable postcodes from origin (or to destination) and get statistics about such postcodes.
|
421
407
|
Currently only supports United Kingdom.
|
422
408
|
|
423
409
|
```ruby
|
@@ -429,8 +415,7 @@ departure_search = {
|
|
429
415
|
travel_time: 1800,
|
430
416
|
coords: { lat: 51.507609, lng: -0.128315 },
|
431
417
|
transportation: { type: 'public_transport' },
|
432
|
-
properties: ['
|
433
|
-
reachable_postcodes_threshold: 0.1
|
418
|
+
properties: ['travel_time', 'distance']
|
434
419
|
}
|
435
420
|
|
436
421
|
arrival_search = {
|
@@ -439,20 +424,19 @@ arrival_search = {
|
|
439
424
|
travel_time: 1800,
|
440
425
|
coords: { lat: 51.507609, lng: -0.128315 },
|
441
426
|
transportation: { type: 'public_transport' },
|
442
|
-
properties: ['
|
443
|
-
reachable_postcodes_threshold: 0.1
|
427
|
+
properties: ['travel_time', 'distance']
|
444
428
|
}
|
445
429
|
|
446
|
-
response = client.
|
447
|
-
departure_searches: [departure_search],
|
430
|
+
response = client.time_filter_postcodes(
|
431
|
+
departure_searches: [departure_search],
|
448
432
|
arrival_searches: [arrival_search]
|
449
433
|
)
|
450
434
|
|
451
435
|
puts response.body
|
452
436
|
```
|
453
437
|
|
454
|
-
### [Time Filter (Postcode
|
455
|
-
Find
|
438
|
+
### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter)
|
439
|
+
Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts.
|
456
440
|
Currently only supports United Kingdom.
|
457
441
|
|
458
442
|
```ruby
|
@@ -478,7 +462,7 @@ arrival_search = {
|
|
478
462
|
reachable_postcodes_threshold: 0.1
|
479
463
|
}
|
480
464
|
|
481
|
-
response = client.
|
465
|
+
response = client.time_filter_postcode_districts(
|
482
466
|
departure_searches: [departure_search],
|
483
467
|
arrival_searches: [arrival_search]
|
484
468
|
)
|
@@ -486,8 +470,8 @@ response = client.time_filter_postcode_sectors(
|
|
486
470
|
puts response.body
|
487
471
|
```
|
488
472
|
|
489
|
-
### [Time Filter (
|
490
|
-
Find
|
473
|
+
### [Time Filter (Postcode Sectors)](https://traveltime.com/docs/api/reference/postcode-sector-filter)
|
474
|
+
Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors.
|
491
475
|
Currently only supports United Kingdom.
|
492
476
|
|
493
477
|
```ruby
|
@@ -499,7 +483,8 @@ departure_search = {
|
|
499
483
|
travel_time: 1800,
|
500
484
|
coords: { lat: 51.507609, lng: -0.128315 },
|
501
485
|
transportation: { type: 'public_transport' },
|
502
|
-
properties: ['
|
486
|
+
properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
|
487
|
+
reachable_postcodes_threshold: 0.1
|
503
488
|
}
|
504
489
|
|
505
490
|
arrival_search = {
|
@@ -508,33 +493,18 @@ arrival_search = {
|
|
508
493
|
travel_time: 1800,
|
509
494
|
coords: { lat: 51.507609, lng: -0.128315 },
|
510
495
|
transportation: { type: 'public_transport' },
|
511
|
-
properties: ['
|
496
|
+
properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
|
497
|
+
reachable_postcodes_threshold: 0.1
|
512
498
|
}
|
513
499
|
|
514
|
-
response = client.
|
515
|
-
departure_searches: [departure_search],
|
500
|
+
response = client.time_filter_postcode_sectors(
|
501
|
+
departure_searches: [departure_search],
|
516
502
|
arrival_searches: [arrival_search]
|
517
503
|
)
|
518
504
|
|
519
505
|
puts response.body
|
520
506
|
```
|
521
507
|
|
522
|
-
### [Geocoding (Search)](https://traveltime.com/docs/api/reference/geocoding-search)
|
523
|
-
Match a query string to geographic coordinates.
|
524
|
-
|
525
|
-
```ruby
|
526
|
-
response = client.geocoding(query: 'London', within_country: 'GB')
|
527
|
-
puts response.body
|
528
|
-
```
|
529
|
-
|
530
|
-
### [Reverse Geocoding](https://traveltime.com/docs/api/reference/geocoding-reverse)
|
531
|
-
Attempt to match a latitude, longitude pair to an address.
|
532
|
-
|
533
|
-
```ruby
|
534
|
-
response = client.reverse_geocoding(lat: 51.506756, lng: -0.128050)
|
535
|
-
puts response.body
|
536
|
-
```
|
537
|
-
|
538
508
|
### [Map Info](https://traveltime.com/docs/api/reference/map-info)
|
539
509
|
Get information about currently supported countries.
|
540
510
|
|
data/lib/travel_time/client.rb
CHANGED
@@ -66,27 +66,25 @@ module TravelTime
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def geocoding(query:, within_country: nil, format_name: nil, exclude: nil, limit: nil, force_postcode: nil,
|
69
|
-
bounds: nil)
|
69
|
+
bounds: nil, accept_language: nil)
|
70
70
|
query = {
|
71
71
|
query: query,
|
72
|
-
'within.country': within_country,
|
72
|
+
'within.country': within_country.is_a?(Array) ? within_country.join(',') : within_country,
|
73
73
|
'format.name': format_name,
|
74
74
|
'format.exclude.country': exclude,
|
75
75
|
limit: limit,
|
76
76
|
'force.add.postcode': force_postcode,
|
77
77
|
bounds: bounds&.join(',')
|
78
78
|
}.compact
|
79
|
-
perform_request { connection.get('geocoding/search', query) }
|
79
|
+
perform_request { connection.get('geocoding/search', query, { 'Accept-Language' => accept_language }) }
|
80
80
|
end
|
81
81
|
|
82
|
-
def reverse_geocoding(lat:, lng:,
|
82
|
+
def reverse_geocoding(lat:, lng:, accept_language: nil)
|
83
83
|
query = {
|
84
84
|
lat: lat,
|
85
|
-
lng: lng
|
86
|
-
'within.country': within_country,
|
87
|
-
'exclude.location.types': exclude
|
85
|
+
lng: lng
|
88
86
|
}.compact
|
89
|
-
perform_request { connection.get('geocoding/reverse', query) }
|
87
|
+
perform_request { connection.get('geocoding/reverse', query, { 'Accept-Language' => accept_language }) }
|
90
88
|
end
|
91
89
|
|
92
90
|
def time_map(departure_searches: nil, arrival_searches: nil, unions: nil, intersections: nil, format: nil)
|
@@ -99,11 +97,9 @@ module TravelTime
|
|
99
97
|
perform_request { connection.post('time-map', payload, { 'Accept' => format }) }
|
100
98
|
end
|
101
99
|
|
102
|
-
def time_map_fast(arrival_searches:,
|
100
|
+
def time_map_fast(arrival_searches:, format: nil)
|
103
101
|
payload = {
|
104
|
-
arrival_searches: arrival_searches
|
105
|
-
unions: unions,
|
106
|
-
intersections: intersections
|
102
|
+
arrival_searches: arrival_searches
|
107
103
|
}.compact
|
108
104
|
perform_request { connection.post('time-map/fast', payload, { 'Accept' => format }) }
|
109
105
|
end
|
@@ -14,7 +14,7 @@ module TravelTime
|
|
14
14
|
def on_request(env)
|
15
15
|
env.request_headers[APP_ID_HEADER] = TravelTime.config.application_id
|
16
16
|
env.request_headers[API_KEY_HEADER] = TravelTime.config.api_key
|
17
|
-
env.request_headers[USER_AGENT] =
|
17
|
+
env.request_headers[USER_AGENT] = "Travel Time Ruby SDK #{TravelTime::VERSION}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/travel_time/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travel_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TravelTime Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|