travel_time 0.7.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dad4d1a6f18d988d831dea4314c3f0f829279ed55448f44c923579fa49d1279
4
- data.tar.gz: 7cfeb8f99c2c2be5145f38db72ba6b6865856d33cf935f401e445ca6d2764a3c
3
+ metadata.gz: 5a23e77e0a13c15dd74597ba0abe967096943c12c51493d9339793e4999d42ca
4
+ data.tar.gz: 8fe9d9beaf181102198577a66a93e3de64611305b720a72e2d9fc89929824291
5
5
  SHA512:
6
- metadata.gz: 4b256ea7bfccf4754389a66a9e30ae4457838b793b295b5d12832408fa169d4c970443753194c2c54f49a73839a675f4d97005a9d1dc626631ab65a909ae55db
7
- data.tar.gz: 5f79e53285c09f08123d8187f60f35882174663da1b85aa95420669ed87b867cb8024e7e5e5907b67398c8f9db520c7c4beed94afad314cdc82924ecec135a13
6
+ metadata.gz: 1bf0ae042c2c1d6f8721a6c9f69b4df925429462894b5d375a5075b0489897249577cc41397ecef6fd75229f3165e4e6acd0f498c02773e0833850199cf2f315
7
+ data.tar.gz: 23e1e54ee47eaf2b3921f8f62b66f3c11d44073997c9d7af545a805c8af621b6727088937c1bae3946544b17bb01fa3267fcfaf10f661a92c6461b2ead90efef
data/README.md CHANGED
@@ -348,16 +348,17 @@ puts response.body
348
348
  ### [Time Filter Fast (Proto)](https://docs.traveltime.com/api/reference/travel-time-distance-matrix-proto)
349
349
  A fast version of time filter communicating using [protocol buffers](https://github.com/protocolbuffers/protobuf).
350
350
 
351
- 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).
352
-
353
- This inflexibility comes with a benefit of faster response times (Over 5x faster compared to regular time filter) and larger limits on the amount of destination points.
354
-
355
351
  Body attributes:
356
352
  * origin: Origin point.
357
353
  * destinations: Destination points. Cannot be more than 200,000.
358
354
  * country: Return the results that are within the specified country.
359
355
  * transport: Transportation type (string) or Transportation object.
360
356
  * traveltime: Time limit.
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:
361
362
 
362
363
  ```ruby
363
364
  origin = {
@@ -375,7 +376,34 @@ response = client.time_filter_fast_proto(
375
376
  origin: origin,
376
377
  destinations: destinations,
377
378
  transport: 'driving+ferry',
378
- traveltime: 7200
379
+ traveltime: 7200,
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
379
407
  )
380
408
  puts(response.body)
381
409
  ```
@@ -501,6 +529,143 @@ response = client.routes(
501
529
  puts response.body
502
530
  ```
503
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
+
504
669
  ### [Geocoding (Search)](https://docs.traveltime.com/api/reference/geocoding-search)
505
670
  Match a query string to geographic coordinates.
506
671
 
@@ -674,11 +839,11 @@ This is optional, but enables you not installing gems to system directories.
674
839
 
675
840
  1. Install RVM: https://rvm.io/
676
841
  2. Optional gnome-terminal integration: https://rvm.io/integration/gnome-terminal
677
- 3. Install and set up Ruby with RVM:
842
+ 3. Install and set up Ruby with RVM (Ruby 3.2 or higher required):
678
843
  ```shell
679
- rvm install ruby-3.2.2
680
- rvm alias create default ruby-3.2.2
681
- rvm use ruby-3.2.2
844
+ rvm install ruby-3.3.8
845
+ rvm alias create default ruby-3.3.8
846
+ rvm use ruby-3.3.8
682
847
  rvm gemset create traveltime-sdk
683
848
  ```
684
849
 
@@ -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,9 +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:)
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
- message = ProtoUtils.make_proto_message(origin, destinations, transport_obj, traveltime)
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)
149
154
  payload = ProtoUtils.encode_proto_message(message)
150
155
  perform_request_proto do
151
156
  proto_connection.post("http://proto.api.traveltimeapp.com/api/v3/#{country}/time-filter/fast/#{transport_obj.url_name}",
@@ -153,18 +158,6 @@ module TravelTime
153
158
  end
154
159
  end
155
160
 
156
- def time_filter_fast_proto_distance(country:, origin:, destinations:, transport:, traveltime:)
157
- transport_obj = Transport.new(transport)
158
- message = ProtoUtils.make_proto_message(origin, destinations, transport_obj, traveltime, properties: [1])
159
- payload = ProtoUtils.encode_proto_message(message)
160
-
161
- # FIXME: proto-with-distance is longer used
162
- perform_request_proto do
163
- proto_connection.post("https://proto-with-distance.api.traveltimeapp.com/api/v3/#{country}/time-filter/fast/#{transport_obj.url_name}",
164
- payload)
165
- end
166
- end
167
-
168
161
  def time_filter_postcodes(departure_searches: nil, arrival_searches: nil)
169
162
  payload = {
170
163
  departure_searches: departure_searches,
@@ -197,5 +190,52 @@ module TravelTime
197
190
  }.compact
198
191
  perform_request { connection.post('routes', payload) }
199
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
200
240
  end
201
241
  end
@@ -56,8 +56,7 @@ module TravelTime
56
56
  @details = {}
57
57
  else
58
58
  @type = transport_input[:type]
59
- # Ruby 3.0+ has #except which is a bit simpler, but using #reject for v2.7 compatibility
60
- @details = transport_input.reject { |k, _| k == :type }
59
+ @details = transport_input.except(:type)
61
60
  validate_details!
62
61
  end
63
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TravelTime
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
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.make_proto_message(origin, destinations, transport_obj, traveltime, properties: nil)
36
- Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new(
37
- oneToManyRequest: make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
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.7.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-07-17 00:00:00.000000000 Z
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.2.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.2.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.7.0
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.1.6
145
+ rubygems_version: 3.5.22
132
146
  signing_key:
133
147
  specification_version: 4
134
148
  summary: TravelTime SDK for Ruby programming language