travel_time 0.6.2 → 0.6.3

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: b5a9aeefc7ffae8034c512e9660c78656c91fa84c71de55f4b5a97c9bfaa6901
4
- data.tar.gz: 2b937c7ac78351fcbae0e18a474496cd360a4aa0a75a97d5c804f97144301e8a
3
+ metadata.gz: 22ddf5718e4967068134f04536b54a127cedde39cb025d43a1050865971d0ec4
4
+ data.tar.gz: 5bad3e0cbfd81665f61cbe40e056eba8ff9104fb1f7881a7b6bd9989881a74e9
5
5
  SHA512:
6
- metadata.gz: 16e978db89506fd9a64eeaa4a16de55e726879ff85c1e2eb8f0ee12079db2a3124ef59bf6c78b80b2dc7ebceb69b9180a2e01933dab04a593f6b175a832894ab
7
- data.tar.gz: 4fea230701c3363d583c00b2419741fb104bacb874669ee55d190bf910dab2fce4c160f1c47d6c9cbfb046a4c29ffa44f4ebe47cc137021a7fe76c9d361bdc40
6
+ metadata.gz: be46a19323f7df166f72bea1e30cbb971d1b4e6bfa5951a23fe049a1c771f59a72fa72964e4d1225588ec061775f155ee27e2ee0d3be4f856addb10e06d7ed9d
7
+ data.tar.gz: 5effc9f42c9a2396d7ddfe75548417e5800ff93b073df6738eb260039c8a769d5aa5b3a41a8a776dc3e62ca59982380dd2857124c822d851d392337a50c5c6d1
data/README.md CHANGED
@@ -356,7 +356,7 @@ Body attributes:
356
356
  * origin: Origin point.
357
357
  * destinations: Destination points. Cannot be more than 200,000.
358
358
  * country: Return the results that are within the specified country.
359
- * transport: Transportation type.
359
+ * transport: Transportation type (string) or Transportation object.
360
360
  * traveltime: Time limit.
361
361
 
362
362
  ```ruby
@@ -382,6 +382,54 @@ puts(response.body)
382
382
 
383
383
  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.
384
384
 
385
+ When picking transportation mode for proto requests take note that some of the transportation modes
386
+ support extra configuration parameters.
387
+
388
+ #### Public Transport Details
389
+
390
+ ```ruby
391
+ response = client.time_filter_fast_proto(
392
+ country: 'UK',
393
+ origin: origin,
394
+ destinations: destinations,
395
+ transport: {
396
+ type: 'pt',
397
+ walking_time_to_station: 900
398
+ },
399
+ traveltime: 7200
400
+ )
401
+ ```
402
+
403
+ * `walking_time_to_station` - limits the possible duration of walking paths.
404
+ This limit is of low precedence and will not override the global travel time limit
405
+ Optional. Must be > 0 and <= 1800.
406
+
407
+ #### Driving and Public Transport Details
408
+
409
+ ```ruby
410
+ response = client.time_filter_fast_proto(
411
+ country: 'UK',
412
+ origin: origin,
413
+ destinations: destinations,
414
+ transport: {
415
+ type: 'driving+pt',
416
+ walking_time_to_station: 900,
417
+ driving_time_to_station: 900,
418
+ parking_time: 200,
419
+ },
420
+ traveltime: 7200
421
+ )
422
+ ```
423
+
424
+ * `walking_time_to_station` - limits the possible duration of walking paths.
425
+ This limit is of low precedence and will not override the global travel time limit.
426
+ Optional. Must be > 0 and <= 1800.
427
+ * `driving_time_to_station` - limits the possible duration of driving paths.
428
+ This limit is of low precedence and will not override the global travel time limit
429
+ Optional. Must be > 0 and <= 1800.
430
+ * `parking_time` - constant penalty to apply to simulate the difficulty of finding a parking spot.
431
+ Optional. Must be non-negative. Cannot be greater than the global travel time limit.
432
+
385
433
  ### [Routes](https://docs.traveltime.com/api/reference/routes)
386
434
  Returns routing information between source and destinations.
387
435
 
@@ -656,6 +704,16 @@ Run `bin/console` for an interactive prompt that will allow you to experiment.
656
704
 
657
705
  To install this gem onto your local machine, run `bundle exec rake install`.
658
706
 
707
+ ### Updating proto files
708
+
709
+ Ruby proto files are currently generated manually and pushed to the repo.
710
+
711
+ If `.proto` files were changed, you can generate Ruby code like this:
712
+
713
+ ```bash
714
+ # For example, if current dir is project root
715
+ protoc --proto_path=lib/travel_time/proto/source --ruby_out=lib lib/travel_time/proto/source/*.proto
716
+
659
717
  ### Release
660
718
 
661
719
  To release a new version, update the version number in `version.rb` and then create a GitHub release. This will trigger
@@ -0,0 +1,72 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: RequestsCommon.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("RequestsCommon.proto", :syntax => :proto3) do
8
+ add_message "com.igeolise.traveltime.rabbitmq.requests.Coords" do
9
+ optional :lat, :float, 1
10
+ optional :lng, :float, 2
11
+ end
12
+ add_message "com.igeolise.traveltime.rabbitmq.requests.Transportation" do
13
+ optional :type, :enum, 1, "com.igeolise.traveltime.rabbitmq.requests.TransportationType"
14
+ oneof :transportationDetails do
15
+ optional :publicTransport, :message, 2, "com.igeolise.traveltime.rabbitmq.requests.PublicTransportDetails"
16
+ optional :drivingAndPublicTransport, :message, 3, "com.igeolise.traveltime.rabbitmq.requests.DrivingAndPublicTransportDetails"
17
+ end
18
+ end
19
+ add_message "com.igeolise.traveltime.rabbitmq.requests.PublicTransportDetails" do
20
+ optional :walkingTimeToStation, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32"
21
+ end
22
+ add_message "com.igeolise.traveltime.rabbitmq.requests.DrivingAndPublicTransportDetails" do
23
+ optional :walkingTimeToStation, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32"
24
+ optional :drivingTimeToStation, :message, 2, "com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32"
25
+ optional :parkingTime, :message, 3, "com.igeolise.traveltime.rabbitmq.requests.OptionalNonNegativeUInt32"
26
+ end
27
+ add_message "com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32" do
28
+ optional :value, :uint32, 1
29
+ end
30
+ add_message "com.igeolise.traveltime.rabbitmq.requests.OptionalNonNegativeUInt32" do
31
+ optional :value, :uint32, 1
32
+ end
33
+ add_enum "com.igeolise.traveltime.rabbitmq.requests.TransportationType" do
34
+ value :PUBLIC_TRANSPORT, 0
35
+ value :DRIVING, 1
36
+ value :DRIVING_AND_PUBLIC_TRANSPORT, 2
37
+ value :DRIVING_AND_FERRY, 3
38
+ value :WALKING, 4
39
+ value :WALKING_AND_FERRY, 7
40
+ value :CYCLING, 5
41
+ value :CYCLING_AND_FERRY, 6
42
+ end
43
+ add_enum "com.igeolise.traveltime.rabbitmq.requests.TimePeriod" do
44
+ value :WEEKDAY_MORNING, 0
45
+ end
46
+ add_enum "com.igeolise.traveltime.rabbitmq.requests.CellPropertyType" do
47
+ value :MEAN, 0
48
+ value :MIN, 1
49
+ value :MAX, 2
50
+ end
51
+ end
52
+ end
53
+
54
+ module Com
55
+ module Igeolise
56
+ module Traveltime
57
+ module Rabbitmq
58
+ module Requests
59
+ Coords = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.Coords").msgclass
60
+ Transportation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.Transportation").msgclass
61
+ PublicTransportDetails = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.PublicTransportDetails").msgclass
62
+ DrivingAndPublicTransportDetails = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.DrivingAndPublicTransportDetails").msgclass
63
+ OptionalPositiveUInt32 = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32").msgclass
64
+ OptionalNonNegativeUInt32 = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.OptionalNonNegativeUInt32").msgclass
65
+ TransportationType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TransportationType").enummodule
66
+ TimePeriod = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimePeriod").enummodule
67
+ CellPropertyType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.CellPropertyType").enummodule
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -3,12 +3,13 @@
3
3
 
4
4
  require 'google/protobuf'
5
5
 
6
- require_relative 'RequestsCommon_pb'
6
+ require 'RequestsCommon_pb'
7
7
 
8
8
  Google::Protobuf::DescriptorPool.generated_pool.build do
9
9
  add_file("TimeFilterFastRequest.proto", :syntax => :proto3) do
10
10
  add_message "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest" do
11
11
  optional :oneToManyRequest, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany"
12
+ optional :manyToOneRequest, :message, 2, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.ManyToOne"
12
13
  end
13
14
  add_message "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany" do
14
15
  optional :departureLocation, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.Coords"
@@ -18,6 +19,14 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
18
19
  optional :travelTime, :sint32, 5
19
20
  repeated :properties, :enum, 6, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property"
20
21
  end
22
+ add_message "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.ManyToOne" do
23
+ optional :arrivalLocation, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.Coords"
24
+ repeated :locationDeltas, :sint32, 2
25
+ optional :transportation, :message, 3, "com.igeolise.traveltime.rabbitmq.requests.Transportation"
26
+ optional :arrivalTimePeriod, :enum, 4, "com.igeolise.traveltime.rabbitmq.requests.TimePeriod"
27
+ optional :travelTime, :sint32, 5
28
+ repeated :properties, :enum, 6, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property"
29
+ end
21
30
  add_enum "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property" do
22
31
  value :FARES, 0
23
32
  value :DISTANCES, 1
@@ -32,6 +41,7 @@ module Com
32
41
  module Requests
33
42
  TimeFilterFastRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest").msgclass
34
43
  TimeFilterFastRequest::OneToMany = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany").msgclass
44
+ TimeFilterFastRequest::ManyToOne = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.ManyToOne").msgclass
35
45
  TimeFilterFastRequest::Property = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property").enummodule
36
46
  end
37
47
  end
@@ -31,6 +31,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
31
31
  value :SOURCE_OUT_OF_REACH, 10
32
32
  value :INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS, 11
33
33
  value :DISTANCE_PROPERTY_NOT_SUPPORTED, 12
34
+ value :BOTH_MANY_TO_ONE_AND_ONE_TO_MANY_CANNOT_BE_SENT, 13
35
+ value :ONE_TO_MANY_OR_MANY_TO_ONE_MUST_NOT_BE_NULL, 14
36
+ value :INVALID_PROTO_REQUEST, 15
34
37
  end
35
38
  end
36
39
  end
@@ -3,6 +3,7 @@
3
3
  require 'faraday'
4
4
  require 'travel_time/middleware/authentication'
5
5
  require 'travel_time/middleware/proto'
6
+ require 'travel_time/transport'
6
7
  require 'limiter'
7
8
 
8
9
  module TravelTime
@@ -143,19 +144,21 @@ module TravelTime
143
144
  end
144
145
 
145
146
  def time_filter_fast_proto(country:, origin:, destinations:, transport:, traveltime:)
146
- message = ProtoUtils.make_proto_message(origin, destinations, transport, traveltime)
147
+ transport_obj = Transport.new(transport)
148
+ message = ProtoUtils.make_proto_message(origin, destinations, transport_obj, traveltime)
147
149
  payload = ProtoUtils.encode_proto_message(message)
148
150
  perform_request_proto do
149
- proto_connection.post("http://proto.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport}",
151
+ proto_connection.post("http://proto.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport_obj.url_name}",
150
152
  payload)
151
153
  end
152
154
  end
153
155
 
154
156
  def time_filter_fast_proto_distance(country:, origin:, destinations:, transport:, traveltime:)
155
- message = ProtoUtils.make_proto_message(origin, destinations, transport, traveltime, properties: [1])
157
+ transport_obj = Transport.new(transport)
158
+ message = ProtoUtils.make_proto_message(origin, destinations, transport_obj, traveltime, properties: [1])
156
159
  payload = ProtoUtils.encode_proto_message(message)
157
160
  perform_request_proto do
158
- proto_connection.post("https://proto-with-distance.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport}",
161
+ proto_connection.post("https://proto-with-distance.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport_obj.url_name}",
159
162
  payload)
160
163
  end
161
164
  end
@@ -9,16 +9,69 @@ message Coords {
9
9
 
10
10
  message Transportation {
11
11
  TransportationType type = 1;
12
+
13
+ // override defaults for some of the transportation modes
14
+ oneof transportationDetails {
15
+ PublicTransportDetails publicTransport = 2;
16
+ DrivingAndPublicTransportDetails drivingAndPublicTransport = 3;
17
+ }
18
+ }
19
+
20
+ // semantically valid only for TransportationType.PUBLIC_TRANSPORT
21
+ message PublicTransportDetails {
22
+ // limits the possible duration of walking paths
23
+ //
24
+ // walkingTimeToStation limit is of low precedence and will not override the global
25
+ // travel time limit
26
+ //
27
+ // walkingTimeToStation must be 0 > and <= 1800
28
+ // if walkingTimeToStation is not set: use service default
29
+ // if walkingTimeToStation > 0: limit the path to at most this value
30
+ OptionalPositiveUInt32 walkingTimeToStation = 1;
31
+ }
32
+
33
+ // semantically valid only for TransportationType.DRIVING_AND_PUBLIC_TRANSPORT
34
+ message DrivingAndPublicTransportDetails {
35
+ // limits the possible duration of walking paths
36
+ //
37
+ // walkingTimeToStation limit is of low precedence and will not override the global
38
+ // travel time limit
39
+ //
40
+ // walkingTimeToStation must be > 0 and <= 1800
41
+ // if walkingTimeToStation is not set: use service default
42
+ // if walkingTimeToStation > 0: limit the walking path to at most this value
43
+ OptionalPositiveUInt32 walkingTimeToStation = 1;
44
+
45
+ // limits the possible duration of driving paths
46
+ //
47
+ // drivingTimeToStation limit is of low precedence and will not override the global
48
+ // travel time limit
49
+ //
50
+ // drivingTimeToStation must be > 0 and <= 1800
51
+ // if drivingTimeToStation is not set: use service default
52
+ // if drivingTimeToStation > 0: limit the path to at most this value
53
+ OptionalPositiveUInt32 drivingTimeToStation = 2;
54
+
55
+ // constant penalty to apply to simulate the difficulty of finding a parking
56
+ // spot
57
+ //
58
+ // if parkingTime < 0: use service default (300s)
59
+ // if parkingTime >= 0: apply the parking penalty when searching for possible
60
+ // paths
61
+ //
62
+ // NOTE: parkingTime penalty cannot be greater than the global travel time
63
+ // limit
64
+ OptionalNonNegativeUInt32 parkingTime = 3;
12
65
  }
13
66
 
14
67
  enum TransportationType {
15
68
  // Considers all paths found by the following steps:
16
69
  // * up to 30 minutes of walking (always included even if no stops found)
17
70
  // * all connections in the 30 minute walking range from public transport
18
- // stops to other public transport stops in travel_time_limit, AND
71
+ // stops to other public transport stops in travel_time_limit, AND
19
72
  // * up to 30 minutes of walking from public transport stops that were visited
20
73
  // by public transport (IOW a path
21
- // [origin]--walking->[stop]--walking-->[destination] is not possible but
74
+ // [origin]--walking->[stop]--walking-->[destination] is not possible but
22
75
  // [origin]--walking->[stop]--public_transport-->[stop]--walking--> is.
23
76
  PUBLIC_TRANSPORT = 0;
24
77
  // Considers all paths found traveling by car from origin(s) to
@@ -30,9 +83,9 @@ enum TransportationType {
30
83
  // to other public transport stops in travel_time_limit, AND
31
84
  // * up to 30 minutes of walking from public transport stops that were visited
32
85
  // by public transport (IOW a path
33
- // [origin]--driving->[stop]--walking-->[destination] is not possible but
86
+ // [origin]--driving->[stop]--walking-->[destination] is not possible but
34
87
  // [origin]--driving->[stop]--public_transport-->[stop]--walking--> is.
35
- // AND/OR
88
+ // AND/OR
36
89
  // * up to 30 minutes of walking
37
90
  //
38
91
  DRIVING_AND_PUBLIC_TRANSPORT = 2;
@@ -59,3 +112,25 @@ enum TransportationType {
59
112
  enum TimePeriod {
60
113
  WEEKDAY_MORNING = 0;
61
114
  }
115
+
116
+ enum CellPropertyType {
117
+ MEAN = 0;
118
+ MIN = 1;
119
+ MAX = 2;
120
+ }
121
+
122
+ // represents an optional positive (strictly greater than 0) uint32 parameter
123
+ //
124
+ // the positive requirement cannot be checked at the protocol level and will
125
+ // only be verified by the server
126
+ message OptionalPositiveUInt32 {
127
+ uint32 value = 1;
128
+ }
129
+
130
+ // represents an optional non negative (greater or equal than 0) uint32 parameter
131
+ //
132
+ // the non negative requirement cannot be checked at the protocol level and will only
133
+ // be verified by the server
134
+ message OptionalNonNegativeUInt32 {
135
+ uint32 value = 1;
136
+ }
@@ -31,5 +31,28 @@ message TimeFilterFastRequest {
31
31
  repeated Property properties = 6;
32
32
  }
33
33
 
34
+ message ManyToOne {
35
+ Coords arrivalLocation = 1;
36
+ /*
37
+ * We encode arrival locations as deltas (relative to the source) using a fixedpoint encoding i.e
38
+ * deltaLat = round((lat - sourceLat) * 10^5).toInt
39
+ * deltaLon = round((lon - sourceLon) * 10^5).toInt
40
+ *
41
+ * The deltas should be interleaved in the `locationDeltas` field i.e
42
+ *
43
+ * locationDeltas[0] should be the first lat
44
+ * locationDeltas[1] should be the first lon
45
+ * locationDeltas[2] should be the second lat
46
+ * ...
47
+ * etc
48
+ */
49
+ repeated sint32 locationDeltas = 2;
50
+ Transportation transportation = 3;
51
+ TimePeriod arrivalTimePeriod = 4;
52
+ sint32 travelTime = 5;
53
+ repeated Property properties = 6;
54
+ }
55
+
34
56
  OneToMany oneToManyRequest = 1;
35
- }
57
+ ManyToOne manyToOneRequest = 2;
58
+ }
@@ -17,68 +17,82 @@ message TimeFilterFastResponse {
17
17
  /*
18
18
  * Catch all unknown error type
19
19
  */
20
- UNKNOWN = 0;
20
+ UNKNOWN = 0 [deprecated = true];
21
21
  /*
22
22
  * oneToManyRequest to many field must not be null
23
23
  */
24
- ONE_TO_MANY_MUST_NOT_BE_NULL = 1;
24
+ ONE_TO_MANY_MUST_NOT_BE_NULL = 1 [deprecated = true];
25
25
  /*
26
26
  * Source (either departure or arrival location) must not be null
27
27
  */
28
- SOURCE_MUST_NOT_BE_NULL = 2;
28
+ SOURCE_MUST_NOT_BE_NULL = 2 [deprecated = true];
29
29
  /*
30
30
  * Transportation mode must not be null.
31
31
  */
32
- TRANSPORTATION_MUST_NOT_BE_NULL = 3;
32
+ TRANSPORTATION_MUST_NOT_BE_NULL = 3 [deprecated = true];
33
33
  /*
34
34
  * Source (either departure or arrival location) must not be null
35
35
  */
36
- SOURCE_NOT_IN_GEOMETRY = 4;
36
+ SOURCE_NOT_IN_GEOMETRY = 4 [deprecated = true];
37
37
 
38
38
  /*
39
39
  * Transportation mode unrecognized.
40
40
  */
41
- UNRECOGNIZED_TRANSPORTATION_MODE = 5;
41
+ UNRECOGNIZED_TRANSPORTATION_MODE = 5 [deprecated = true];
42
42
 
43
43
  /*
44
44
  * The travel time limit is too low to process this request.
45
45
  */
46
- TRAVEL_TIME_LIMIT_TOO_LOW = 6;
46
+ TRAVEL_TIME_LIMIT_TOO_LOW = 6 [deprecated = true];
47
47
 
48
48
  /*
49
49
  * The travel time limit is too high to process this request.
50
50
  */
51
- TRAVEL_TIME_LIMIT_TOO_HIGH = 7;
51
+ TRAVEL_TIME_LIMIT_TOO_HIGH = 7 [deprecated = true];
52
52
 
53
53
  /*
54
54
  * User id not set.
55
55
  */
56
- AUTH_ERROR_NO_USER_ID = 8;
56
+ AUTH_ERROR_NO_USER_ID = 8 [deprecated = true];
57
57
 
58
58
  /*
59
59
  * Message sent to wrong queue - transportation mode cannot be handled.
60
60
  */
61
- SERVICE_MISMATCH_WRONG_TRANSPORTATION_MODE = 9;
61
+ SERVICE_MISMATCH_WRONG_TRANSPORTATION_MODE = 9 [deprecated = true];
62
62
 
63
63
  /*
64
64
  * Source is in a area that doesn't have any points that can be out of
65
65
  * search e.g a lake, mountains or other desolate areas.
66
66
  */
67
- SOURCE_OUT_OF_REACH = 10;
67
+ SOURCE_OUT_OF_REACH = 10 [deprecated = true];
68
68
 
69
69
  /*
70
70
  * The interleaved deltas array should have (lat/lon) deltas and have an
71
71
  * even number of elements
72
72
  */
73
- INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS = 11;
73
+ INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS = 11 [deprecated = true];
74
74
 
75
75
  /*
76
76
  * Public transport requests do not support returning distances for
77
77
  * returned points.
78
78
  */
79
- DISTANCE_PROPERTY_NOT_SUPPORTED = 12;
79
+ DISTANCE_PROPERTY_NOT_SUPPORTED = 12 [deprecated = true];
80
+
81
+ /*
82
+ * ManyToOne and OneToMany cannot be sent at the same time
83
+ */
84
+ BOTH_MANY_TO_ONE_AND_ONE_TO_MANY_CANNOT_BE_SENT = 13 [deprecated = true];
85
+
86
+ /*
87
+ * ManyToOne or OneToMany cannot be null
88
+ */
89
+ ONE_TO_MANY_OR_MANY_TO_ONE_MUST_NOT_BE_NULL = 14 [deprecated = true];
90
+ /*
91
+ * Invalid proto request
92
+ */
93
+ INVALID_PROTO_REQUEST = 15 [deprecated = true];
80
94
  }
81
95
 
82
- Error error = 1;
96
+ Error error = 1 [deprecated = true];
83
97
  Properties properties = 2;
84
98
  }
@@ -19,7 +19,7 @@ module TravelTime
19
19
  new(
20
20
  status: response.status,
21
21
  headers: response.headers,
22
- body: ProtoUtils.decode_proto_response(response.body)
22
+ body: response.success? ? ProtoUtils.decode_proto_response(response.body) : nil
23
23
  )
24
24
  end
25
25
 
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TravelTime
4
+ # The Transport class provides a way to set transportation details
5
+ class Transport
6
+ attr_reader :type, :code, :url_name, :details
7
+
8
+ # Define allowed details for each transport type
9
+ ALLOWED_DETAILS = {
10
+ 'pt' => %i[walking_time_to_station],
11
+ 'driving+pt' => %i[walking_time_to_station driving_time_to_station parking_time]
12
+ }.freeze
13
+
14
+ PROTO_TRANSPORT_MAP = {
15
+ pt: { code: 0, url_name: 'pt' },
16
+ 'driving+pt': { code: 2, url_name: 'pt' },
17
+ driving: { code: 1, url_name: 'driving' },
18
+ walking: { code: 4, url_name: 'walking' },
19
+ cycling: { code: 5, url_name: 'driving' },
20
+ 'driving+ferry': { code: 3, url_name: 'driving+ferry' },
21
+ 'cycling+ferry': { code: 6, url_name: 'cycling+ferry' },
22
+ 'walking+ferry': { code: 7, url_name: 'walking+ferry' }
23
+ }.freeze
24
+
25
+ def initialize(transport_input)
26
+ setup_type_and_details(transport_input)
27
+ set_transport_info
28
+ end
29
+
30
+ # Validate that the provided details are allowed for this transport type
31
+ def validate_details!
32
+ return if @details.empty?
33
+
34
+ validate_transport_type_supports_details
35
+ validate_unexpected_details
36
+ end
37
+
38
+ def apply_to_proto(transportation)
39
+ # Set the base type
40
+ transportation.type = @code
41
+
42
+ # Apply PublicTransport details - Only for type "pt" (code 0)
43
+ apply_public_transport_details(transportation) if @code.zero? && @details[:walking_time_to_station]
44
+
45
+ # Apply DrivingAndPublicTransport details - Only for type "driving+pt" (code 2)
46
+ apply_driving_pt_details(transportation) if @code == 2
47
+
48
+ transportation
49
+ end
50
+
51
+ private
52
+
53
+ def setup_type_and_details(transport_input)
54
+ if transport_input.is_a?(String)
55
+ @type = transport_input
56
+ @details = {}
57
+ else
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 }
61
+ validate_details!
62
+ end
63
+ end
64
+
65
+ def set_transport_info
66
+ info = PROTO_TRANSPORT_MAP[@type.to_sym]
67
+ @code = info[:code]
68
+ @url_name = info[:url_name]
69
+ end
70
+
71
+ def validate_transport_type_supports_details
72
+ return if ALLOWED_DETAILS.key?(@type)
73
+
74
+ detail_keys = @details.keys
75
+ error_msg = "Transport type '#{@type}' doesn't support additional details, but #{detail_keys.join(', ')} provided"
76
+ raise ArgumentError, error_msg
77
+ end
78
+
79
+ def validate_unexpected_details
80
+ allowed = ALLOWED_DETAILS[@type]
81
+ unexpected = @details.keys - allowed
82
+
83
+ return if unexpected.empty?
84
+
85
+ allowed_msg = allowed.empty? ? 'no details' : allowed.join(', ')
86
+ error_msg = "Unexpected details for transport type '#{@type}': #{unexpected.join(', ')}. Allowed: #{allowed_msg}"
87
+ raise ArgumentError, error_msg
88
+ end
89
+
90
+ def create_positive_uint32(value)
91
+ Com::Igeolise::Traveltime::Rabbitmq::Requests::OptionalPositiveUInt32.new(value: value)
92
+ end
93
+
94
+ def create_non_negative_uint32(value)
95
+ Com::Igeolise::Traveltime::Rabbitmq::Requests::OptionalNonNegativeUInt32.new(value: value)
96
+ end
97
+
98
+ def set_optional_fields(details_obj, field_mappings)
99
+ field_mappings.each do |detail_key, field_info|
100
+ field_name, creator_method = field_info
101
+
102
+ details_obj.send("#{field_name}=", send(creator_method, @details[detail_key])) if @details.key?(detail_key)
103
+ end
104
+ end
105
+
106
+ # Simplified methods for each transportation type
107
+ def apply_public_transport_details(transportation)
108
+ return unless @details[:walking_time_to_station]
109
+
110
+ transport_details = Com::Igeolise::Traveltime::Rabbitmq::Requests::PublicTransportDetails.new
111
+ set_optional_fields(
112
+ transport_details, {
113
+ walking_time_to_station: %i[walkingTimeToStation create_positive_uint32]
114
+ }
115
+ )
116
+
117
+ transportation.publicTransport = transport_details
118
+ end
119
+
120
+ def apply_driving_pt_details(transportation)
121
+ return unless need_driving_pt_details?
122
+
123
+ transport_details = Com::Igeolise::Traveltime::Rabbitmq::Requests::DrivingAndPublicTransportDetails.new
124
+ set_optional_fields(
125
+ transport_details, {
126
+ walking_time_to_station: %i[walkingTimeToStation create_positive_uint32],
127
+ driving_time_to_station: %i[drivingTimeToStation create_positive_uint32],
128
+ parking_time: %i[parkingTime create_non_negative_uint32]
129
+ }
130
+ )
131
+
132
+ transportation.drivingAndPublicTransport = transport_details
133
+ end
134
+
135
+ def need_driving_pt_details?
136
+ @details[:walking_time_to_station] ||
137
+ @details[:driving_time_to_station] ||
138
+ @details.key?(:parking_time)
139
+ end
140
+ end
141
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TravelTime
4
- VERSION = '0.6.2'
4
+ VERSION = '0.6.3'
5
5
  end
data/lib/travel_time.rb CHANGED
@@ -5,7 +5,7 @@ require 'travel_time/client'
5
5
  require 'travel_time/error'
6
6
  require 'travel_time/response'
7
7
  require 'travel_time/version'
8
- require 'travel_time/proto/utils'
8
+ require 'utils'
9
9
 
10
10
  # Main TravelTime module
11
11
  module TravelTime
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'travel_time/proto/v2/RequestsCommon_pb'
4
- require 'travel_time/proto/v2/TimeFilterFastRequest_pb'
5
- require 'travel_time/proto/v2/TimeFilterFastResponse_pb'
3
+ require 'RequestsCommon_pb'
4
+ require 'TimeFilterFastRequest_pb'
5
+ require 'TimeFilterFastResponse_pb'
6
6
 
7
7
  module TravelTime
8
8
  # Utilities for encoding/decoding protobuf requests
@@ -19,32 +19,22 @@ module TravelTime
19
19
  deltas.flatten
20
20
  end
21
21
 
22
- def self.get_proto_transport_code(transport)
23
- proto_transport_map = {
24
- pt: 0,
25
- 'driving+ferry': 3,
26
- 'cycling+ferry': 6,
27
- 'walking+ferry': 7
28
- }
29
- proto_transport_map[transport.to_sym]
30
- end
31
-
32
- def self.make_one_to_many(origin, destinations, transport, traveltime, properties)
22
+ def self.make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
23
+ transportation = Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new
24
+ transport_obj.apply_to_proto(transportation)
33
25
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::OneToMany.new(
34
26
  departureLocation: origin,
35
27
  locationDeltas: build_deltas(origin, destinations),
36
- transportation: Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new(
37
- { type: get_proto_transport_code(transport) }
38
- ),
28
+ transportation: transportation,
39
29
  arrivalTimePeriod: 0,
40
30
  travelTime: traveltime,
41
31
  properties: properties
42
32
  )
43
33
  end
44
34
 
45
- def self.make_proto_message(origin, destinations, transport, traveltime, properties: nil)
35
+ def self.make_proto_message(origin, destinations, transport_obj, traveltime, properties: nil)
46
36
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new(
47
- oneToManyRequest: make_one_to_many(origin, destinations, transport, traveltime, properties)
37
+ oneToManyRequest: make_one_to_many(origin, destinations, transport_obj, traveltime, properties)
48
38
  )
49
39
  end
50
40
 
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.6.2
4
+ version: 0.6.3
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-01-29 00:00:00.000000000 Z
11
+ date: 2025-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -91,6 +91,9 @@ files:
91
91
  - Rakefile
92
92
  - bin/console
93
93
  - bin/setup
94
+ - lib/RequestsCommon_pb.rb
95
+ - lib/TimeFilterFastRequest_pb.rb
96
+ - lib/TimeFilterFastResponse_pb.rb
94
97
  - lib/travel_time.rb
95
98
  - lib/travel_time/client.rb
96
99
  - lib/travel_time/error.rb
@@ -99,12 +102,10 @@ files:
99
102
  - lib/travel_time/proto/source/RequestsCommon.proto
100
103
  - lib/travel_time/proto/source/TimeFilterFastRequest.proto
101
104
  - lib/travel_time/proto/source/TimeFilterFastResponse.proto
102
- - lib/travel_time/proto/utils.rb
103
- - lib/travel_time/proto/v2/RequestsCommon_pb.rb
104
- - lib/travel_time/proto/v2/TimeFilterFastRequest_pb.rb
105
- - lib/travel_time/proto/v2/TimeFilterFastResponse_pb.rb
106
105
  - lib/travel_time/response.rb
106
+ - lib/travel_time/transport.rb
107
107
  - lib/travel_time/version.rb
108
+ - lib/utils.rb
108
109
  homepage: https://traveltime.com
109
110
  licenses:
110
111
  - MIT
@@ -1,44 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: RequestsCommon.proto
3
-
4
- require 'google/protobuf'
5
-
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_file("RequestsCommon.proto", :syntax => :proto3) do
8
- add_message "com.igeolise.traveltime.rabbitmq.requests.Coords" do
9
- optional :lat, :float, 1
10
- optional :lng, :float, 2
11
- end
12
- add_message "com.igeolise.traveltime.rabbitmq.requests.Transportation" do
13
- optional :type, :enum, 1, "com.igeolise.traveltime.rabbitmq.requests.TransportationType"
14
- end
15
- add_enum "com.igeolise.traveltime.rabbitmq.requests.TransportationType" do
16
- value :PUBLIC_TRANSPORT, 0
17
- value :DRIVING, 1
18
- value :DRIVING_AND_PUBLIC_TRANSPORT, 2
19
- value :DRIVING_AND_FERRY, 3
20
- value :WALKING, 4
21
- value :WALKING_AND_FERRY, 7
22
- value :CYCLING, 5
23
- value :CYCLING_AND_FERRY, 6
24
- end
25
- add_enum "com.igeolise.traveltime.rabbitmq.requests.TimePeriod" do
26
- value :WEEKDAY_MORNING, 0
27
- end
28
- end
29
- end
30
-
31
- module Com
32
- module Igeolise
33
- module Traveltime
34
- module Rabbitmq
35
- module Requests
36
- Coords = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.Coords").msgclass
37
- Transportation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.Transportation").msgclass
38
- TransportationType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TransportationType").enummodule
39
- TimePeriod = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimePeriod").enummodule
40
- end
41
- end
42
- end
43
- end
44
- end