travel_time 0.7.1 → 0.8.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/README.md +172 -5
- data/lib/travel_time/client.rb +54 -5
- data/lib/travel_time/transport.rb +1 -2
- data/lib/travel_time/version.rb +1 -1
- data/lib/utils.rb +29 -3
- metadata +20 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a23e77e0a13c15dd74597ba0abe967096943c12c51493d9339793e4999d42ca
|
|
4
|
+
data.tar.gz: 8fe9d9beaf181102198577a66a93e3de64611305b720a72e2d9fc89929824291
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bf0ae042c2c1d6f8721a6c9f69b4df925429462894b5d375a5075b0489897249577cc41397ecef6fd75229f3165e4e6acd0f498c02773e0833850199cf2f315
|
|
7
|
+
data.tar.gz: 23e1e54ee47eaf2b3921f8f62b66f3c11d44073997c9d7af545a805c8af621b6727088937c1bae3946544b17bb01fa3267fcfaf10f661a92c6461b2ead90efef
|
data/README.md
CHANGED
|
@@ -355,6 +355,10 @@ Body attributes:
|
|
|
355
355
|
* transport: Transportation type (string) or Transportation object.
|
|
356
356
|
* traveltime: Time limit.
|
|
357
357
|
* with_distance: (Optional) If true, returns distances in addition to travel times.
|
|
358
|
+
* request_type: (Optional) Specifies the request type - either `TravelTime::ProtoUtils::ONE_TO_MANY` (default) or `TravelTime::ProtoUtils::MANY_TO_ONE`.
|
|
359
|
+
|
|
360
|
+
#### One-to-Many (default)
|
|
361
|
+
Search from a single origin to multiple destinations:
|
|
358
362
|
|
|
359
363
|
```ruby
|
|
360
364
|
origin = {
|
|
@@ -373,7 +377,33 @@ response = client.time_filter_fast_proto(
|
|
|
373
377
|
destinations: destinations,
|
|
374
378
|
transport: 'driving+ferry',
|
|
375
379
|
traveltime: 7200,
|
|
376
|
-
with_distance: true # To also get distances, optional
|
|
380
|
+
with_distance: true, # To also get distances, optional
|
|
381
|
+
request_type: TravelTime::ProtoUtils::ONE_TO_MANY # Optional
|
|
382
|
+
)
|
|
383
|
+
puts(response.body)
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
#### Many-to-One
|
|
387
|
+
Search from multiple origins to a single destination:
|
|
388
|
+
|
|
389
|
+
```ruby
|
|
390
|
+
arrival = {
|
|
391
|
+
lat: 51.508930,
|
|
392
|
+
lng: -0.131387,
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
origins = [
|
|
396
|
+
{ lat: 51.508824, lng: -0.167093 },
|
|
397
|
+
{ lat: 51.536067, lng: -0.153596 }
|
|
398
|
+
]
|
|
399
|
+
|
|
400
|
+
response = client.time_filter_fast_proto(
|
|
401
|
+
country: 'UK',
|
|
402
|
+
origin: arrival, # arrival/destination point
|
|
403
|
+
destinations: origins, # departure/origin points
|
|
404
|
+
transport: 'public_transport',
|
|
405
|
+
traveltime: 3600,
|
|
406
|
+
request_type: TravelTime::ProtoUtils::MANY_TO_ONE
|
|
377
407
|
)
|
|
378
408
|
puts(response.body)
|
|
379
409
|
```
|
|
@@ -499,6 +529,143 @@ response = client.routes(
|
|
|
499
529
|
puts response.body
|
|
500
530
|
```
|
|
501
531
|
|
|
532
|
+
### [H3](https://docs.traveltime.com/api/reference/h3)
|
|
533
|
+
Returns travel time statistics for H3 cells in catchment areas.
|
|
534
|
+
|
|
535
|
+
Body attributes:
|
|
536
|
+
* resolution: H3 resolution level (higher = more granular cells).
|
|
537
|
+
Limitations can be found [here](https://docs.traveltime.com/api/reference/h3#limits-of-resolution-and-traveltime).
|
|
538
|
+
* properties: Statistical properties to calculate for each H3 cell ('min', 'max', 'mean').
|
|
539
|
+
* departure_searches: Departure-based searches with specific departure times.
|
|
540
|
+
* arrival_searches: Arrival-based searches with specific arrival times.
|
|
541
|
+
* unions: Union operations combining multiple search results.
|
|
542
|
+
* intersections: Intersection operations finding overlapping areas.
|
|
543
|
+
|
|
544
|
+
```ruby
|
|
545
|
+
require 'time'
|
|
546
|
+
|
|
547
|
+
departure_search = {
|
|
548
|
+
id: 'public transport from Trafalgar Square',
|
|
549
|
+
departure_time: Time.now.iso8601,
|
|
550
|
+
travel_time: 1800,
|
|
551
|
+
coords: { lat: 51.507609, lng: -0.128315 },
|
|
552
|
+
transportation: { type: 'public_transport' }
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
arrival_search = {
|
|
556
|
+
id: 'public transport to Hyde Park',
|
|
557
|
+
arrival_time: Time.now.iso8601,
|
|
558
|
+
travel_time: 1800,
|
|
559
|
+
coords: { lat: 51.508530, lng: -0.163925 },
|
|
560
|
+
transportation: { type: 'public_transport' }
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
response = client.h3(
|
|
564
|
+
resolution: 5,
|
|
565
|
+
properties: ['min', 'max', 'mean'],
|
|
566
|
+
departure_searches: [departure_search],
|
|
567
|
+
arrival_searches: [arrival_search]
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
puts response.body
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
### [H3 Fast](https://docs.traveltime.com/api/reference/h3-fast)
|
|
574
|
+
A high performance version of the H3 endpoint. Returns travel time statistics for H3 cells in catchment areas.
|
|
575
|
+
|
|
576
|
+
Body attributes:
|
|
577
|
+
* resolution: H3 resolution level (higher = more granular cells, allowed values differ based on `travel_time`.
|
|
578
|
+
Limitations can be found [here](https://docs.traveltime.com/api/reference/h3-fast#limits-of-resolution-and-traveltime).
|
|
579
|
+
* properties: Statistical properties to calculate for each H3 cell ('min', 'max', 'mean').
|
|
580
|
+
* arrival_searches: Arrival-based searches with specific arrival times.
|
|
581
|
+
* unions: Union operations combining multiple search results.
|
|
582
|
+
* intersections: Intersection operations finding overlapping areas.
|
|
583
|
+
|
|
584
|
+
```ruby
|
|
585
|
+
require 'time'
|
|
586
|
+
|
|
587
|
+
arrival_search = {
|
|
588
|
+
one_to_many: [{
|
|
589
|
+
id: 'public transport from Trafalgar Square',
|
|
590
|
+
arrival_time_period: 'weekday_morning',
|
|
591
|
+
travel_time: 1800,
|
|
592
|
+
coords: { lat: 51.507609, lng: -0.128315 },
|
|
593
|
+
transportation: { type: 'public_transport' }
|
|
594
|
+
}]
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
response = client.h3_fast(
|
|
598
|
+
resolution: 5,
|
|
599
|
+
properties: ['min', 'max', 'mean'],
|
|
600
|
+
arrival_searches: arrival_search
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
puts response.body
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### [Geohash](https://docs.traveltime.com/api/reference/geohash)
|
|
607
|
+
Returns travel times to geohash cells within travel time catchment areas.
|
|
608
|
+
|
|
609
|
+
Body attributes:
|
|
610
|
+
* resolution: Geohash resolution level (1-6).
|
|
611
|
+
* properties: Statistical properties to calculate for each geohash cell ('min', 'max', 'mean').
|
|
612
|
+
* departure_searches: Departure-based searches with specific departure times.
|
|
613
|
+
* arrival_searches: Arrival-based searches with specific arrival time.
|
|
614
|
+
* unions: Union operations combining multiple search results.
|
|
615
|
+
* intersections: Intersection operations finding overlapping areas.
|
|
616
|
+
|
|
617
|
+
```ruby
|
|
618
|
+
require 'time'
|
|
619
|
+
|
|
620
|
+
departure_search = {
|
|
621
|
+
id: 'public transport from Trafalgar Square',
|
|
622
|
+
departure_time: Time.now.iso8601,
|
|
623
|
+
travel_time: 1800,
|
|
624
|
+
coords: { lat: 51.507609, lng: -0.128315 },
|
|
625
|
+
transportation: { type: 'public_transport' }
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
response = client.geohash(
|
|
629
|
+
resolution: 3,
|
|
630
|
+
properties: ['min', 'max', 'mean'],
|
|
631
|
+
departure_searches: [departure_search]
|
|
632
|
+
)
|
|
633
|
+
|
|
634
|
+
puts response.body
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### [Geohash Fast](https://docs.traveltime.com/api/reference/geohash-fast)
|
|
638
|
+
A high performance version of the Geohash endpoint. Returns travel times to geohash cells within travel time catchment areas.
|
|
639
|
+
|
|
640
|
+
Body attributes:
|
|
641
|
+
* resolution: Geohash resolution level (1-6).
|
|
642
|
+
* properties: Statistical properties to calculate for each geohash cell ('min', 'max', 'mean').
|
|
643
|
+
* arrival_searches: Arrival-based searches with specific arrival times.
|
|
644
|
+
* unions: Union operations combining multiple search results.
|
|
645
|
+
* intersections: Intersection operations finding overlapping areas.
|
|
646
|
+
|
|
647
|
+
```ruby
|
|
648
|
+
require 'time'
|
|
649
|
+
|
|
650
|
+
arrival_search = {
|
|
651
|
+
one_to_many: [{
|
|
652
|
+
id: 'public transport from Trafalgar Square',
|
|
653
|
+
arrival_time_period: 'weekday_morning',
|
|
654
|
+
travel_time: 1800,
|
|
655
|
+
coords: { lat: 51.507609, lng: -0.128315 },
|
|
656
|
+
transportation: { type: 'public_transport' }
|
|
657
|
+
}]
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
response = client.geohash_fast(
|
|
661
|
+
resolution: 3,
|
|
662
|
+
properties: ['min', 'max', 'mean'],
|
|
663
|
+
arrival_searches: arrival_search
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
puts response.body
|
|
667
|
+
```
|
|
668
|
+
|
|
502
669
|
### [Geocoding (Search)](https://docs.traveltime.com/api/reference/geocoding-search)
|
|
503
670
|
Match a query string to geographic coordinates.
|
|
504
671
|
|
|
@@ -672,11 +839,11 @@ This is optional, but enables you not installing gems to system directories.
|
|
|
672
839
|
|
|
673
840
|
1. Install RVM: https://rvm.io/
|
|
674
841
|
2. Optional gnome-terminal integration: https://rvm.io/integration/gnome-terminal
|
|
675
|
-
3. Install and set up Ruby with RVM:
|
|
842
|
+
3. Install and set up Ruby with RVM (Ruby 3.2 or higher required):
|
|
676
843
|
```shell
|
|
677
|
-
rvm install ruby-3.
|
|
678
|
-
rvm alias create default ruby-3.
|
|
679
|
-
rvm use ruby-3.
|
|
844
|
+
rvm install ruby-3.3.8
|
|
845
|
+
rvm alias create default ruby-3.3.8
|
|
846
|
+
rvm use ruby-3.3.8
|
|
680
847
|
rvm gemset create traveltime-sdk
|
|
681
848
|
```
|
|
682
849
|
|
data/lib/travel_time/client.rb
CHANGED
|
@@ -10,6 +10,7 @@ module TravelTime
|
|
|
10
10
|
# The Client class provides the main interface to interact with the TravelTime API
|
|
11
11
|
class Client # rubocop:disable Metrics/ClassLength
|
|
12
12
|
extend Limiter::Mixin
|
|
13
|
+
|
|
13
14
|
API_BASE_URL = 'https://api.traveltimeapp.com/v4/'
|
|
14
15
|
|
|
15
16
|
attr_reader :connection, :proto_connection
|
|
@@ -143,12 +144,13 @@ module TravelTime
|
|
|
143
144
|
perform_request { connection.post('time-filter/fast', payload) }
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def time_filter_fast_proto(country:, origin:, destinations:, transport:, traveltime:, with_distance: false
|
|
147
|
+
def time_filter_fast_proto(country:, origin:, destinations:, transport:, traveltime:, with_distance: false,
|
|
148
|
+
request_type: nil)
|
|
147
149
|
transport_obj = Transport.new(transport)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
distance_prop = Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::Property::DISTANCES
|
|
151
|
+
properties = with_distance ? [distance_prop] : nil
|
|
152
|
+
message = ProtoUtils.make_proto_message(origin, destinations, transport_obj, traveltime,
|
|
153
|
+
properties: properties, request_type: request_type)
|
|
152
154
|
payload = ProtoUtils.encode_proto_message(message)
|
|
153
155
|
perform_request_proto do
|
|
154
156
|
proto_connection.post("http://proto.api.traveltimeapp.com/api/v3/#{country}/time-filter/fast/#{transport_obj.url_name}",
|
|
@@ -188,5 +190,52 @@ module TravelTime
|
|
|
188
190
|
}.compact
|
|
189
191
|
perform_request { connection.post('routes', payload) }
|
|
190
192
|
end
|
|
193
|
+
|
|
194
|
+
def h3(resolution:, properties:, departure_searches: nil, arrival_searches: nil, unions: nil, intersections: nil)
|
|
195
|
+
payload = {
|
|
196
|
+
resolution: resolution,
|
|
197
|
+
properties: properties,
|
|
198
|
+
departure_searches: departure_searches,
|
|
199
|
+
arrival_searches: arrival_searches,
|
|
200
|
+
unions: unions,
|
|
201
|
+
intersections: intersections
|
|
202
|
+
}.compact
|
|
203
|
+
perform_request { connection.post('h3', payload) }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def h3_fast(resolution:, properties:, arrival_searches:, unions: nil, intersections: nil)
|
|
207
|
+
payload = {
|
|
208
|
+
resolution: resolution,
|
|
209
|
+
properties: properties,
|
|
210
|
+
arrival_searches: arrival_searches,
|
|
211
|
+
unions: unions,
|
|
212
|
+
intersections: intersections
|
|
213
|
+
}.compact
|
|
214
|
+
perform_request { connection.post('h3/fast', payload) }
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def geohash(resolution:, properties:, departure_searches: nil, arrival_searches: nil, unions: nil,
|
|
218
|
+
intersections: nil)
|
|
219
|
+
payload = {
|
|
220
|
+
resolution: resolution,
|
|
221
|
+
properties: properties,
|
|
222
|
+
departure_searches: departure_searches,
|
|
223
|
+
arrival_searches: arrival_searches,
|
|
224
|
+
unions: unions,
|
|
225
|
+
intersections: intersections
|
|
226
|
+
}.compact
|
|
227
|
+
perform_request { connection.post('geohash', payload) }
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def geohash_fast(resolution:, properties:, arrival_searches:, unions: nil, intersections: nil)
|
|
231
|
+
payload = {
|
|
232
|
+
resolution: resolution,
|
|
233
|
+
properties: properties,
|
|
234
|
+
arrival_searches: arrival_searches,
|
|
235
|
+
unions: unions,
|
|
236
|
+
intersections: intersections
|
|
237
|
+
}.compact
|
|
238
|
+
perform_request { connection.post('geohash/fast', payload) }
|
|
239
|
+
end
|
|
191
240
|
end
|
|
192
241
|
end
|
|
@@ -56,8 +56,7 @@ module TravelTime
|
|
|
56
56
|
@details = {}
|
|
57
57
|
else
|
|
58
58
|
@type = transport_input[:type]
|
|
59
|
-
|
|
60
|
-
@details = transport_input.reject { |k, _| k == :type }
|
|
59
|
+
@details = transport_input.except(:type)
|
|
61
60
|
validate_details!
|
|
62
61
|
end
|
|
63
62
|
end
|
data/lib/travel_time/version.rb
CHANGED
data/lib/utils.rb
CHANGED
|
@@ -7,6 +7,10 @@ require 'TimeFilterFastResponse_pb'
|
|
|
7
7
|
module TravelTime
|
|
8
8
|
# Utilities for encoding/decoding protobuf requests
|
|
9
9
|
class ProtoUtils
|
|
10
|
+
# Request type constants
|
|
11
|
+
ONE_TO_MANY = :one_to_many
|
|
12
|
+
MANY_TO_ONE = :many_to_one
|
|
13
|
+
|
|
10
14
|
def self.encode_fixed_point(source, target)
|
|
11
15
|
((target - source) * 10.pow(5)).round
|
|
12
16
|
end
|
|
@@ -32,12 +36,34 @@ module TravelTime
|
|
|
32
36
|
)
|
|
33
37
|
end
|
|
34
38
|
|
|
35
|
-
def self.
|
|
36
|
-
Com::Igeolise::Traveltime::Rabbitmq::Requests::
|
|
37
|
-
|
|
39
|
+
def self.make_many_to_one(arrival, origins, transport_obj, traveltime, properties)
|
|
40
|
+
transportation = Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new
|
|
41
|
+
transport_obj.apply_to_proto(transportation)
|
|
42
|
+
Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::ManyToOne.new(
|
|
43
|
+
arrivalLocation: arrival,
|
|
44
|
+
locationDeltas: build_deltas(arrival, origins),
|
|
45
|
+
transportation: transportation,
|
|
46
|
+
arrivalTimePeriod: 0,
|
|
47
|
+
travelTime: traveltime,
|
|
48
|
+
properties: properties
|
|
38
49
|
)
|
|
39
50
|
end
|
|
40
51
|
|
|
52
|
+
def self.make_proto_message(origin, destinations, transport_obj, traveltime, properties: nil, request_type: nil)
|
|
53
|
+
request_type ||= ONE_TO_MANY
|
|
54
|
+
request = Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new
|
|
55
|
+
|
|
56
|
+
if request_type == ONE_TO_MANY
|
|
57
|
+
request.oneToManyRequest = make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
|
|
58
|
+
elsif request_type == MANY_TO_ONE
|
|
59
|
+
request.manyToOneRequest = make_many_to_one(origin, destinations, transport_obj, traveltime, properties)
|
|
60
|
+
else
|
|
61
|
+
raise ArgumentError, "Invalid request_type: #{request_type}. Must be ONE_TO_MANY or MANY_TO_ONE"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
request
|
|
65
|
+
end
|
|
66
|
+
|
|
41
67
|
def self.encode_proto_message(message)
|
|
42
68
|
Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.encode(message)
|
|
43
69
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: travel_time
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TravelTime Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: base64
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.3.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.3.0
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: dry-configurable
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -70,14 +84,14 @@ dependencies:
|
|
|
70
84
|
requirements:
|
|
71
85
|
- - "~>"
|
|
72
86
|
- !ruby/object:Gem::Version
|
|
73
|
-
version: 2.
|
|
87
|
+
version: 2.3.0
|
|
74
88
|
type: :runtime
|
|
75
89
|
prerelease: false
|
|
76
90
|
version_requirements: !ruby/object:Gem::Requirement
|
|
77
91
|
requirements:
|
|
78
92
|
- - "~>"
|
|
79
93
|
- !ruby/object:Gem::Version
|
|
80
|
-
version: 2.
|
|
94
|
+
version: 2.3.0
|
|
81
95
|
description: TravelTime SDK for Ruby programming language
|
|
82
96
|
email:
|
|
83
97
|
- support@traveltime.com
|
|
@@ -121,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
121
135
|
requirements:
|
|
122
136
|
- - ">="
|
|
123
137
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 2.
|
|
138
|
+
version: 3.2.0
|
|
125
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
140
|
requirements:
|
|
127
141
|
- - ">="
|
|
128
142
|
- !ruby/object:Gem::Version
|
|
129
143
|
version: '0'
|
|
130
144
|
requirements: []
|
|
131
|
-
rubygems_version: 3.
|
|
145
|
+
rubygems_version: 3.5.22
|
|
132
146
|
signing_key:
|
|
133
147
|
specification_version: 4
|
|
134
148
|
summary: TravelTime SDK for Ruby programming language
|