travel_time 0.8.0 → 0.9.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 +35 -2
- data/lib/RequestsCommon_pb.rb +24 -44
- data/lib/TimeFilterFastRequest_pb.rb +25 -25
- data/lib/TimeFilterFastResponse_pb.rb +24 -31
- data/lib/travel_time/client.rb +12 -6
- data/lib/travel_time/error.rb +3 -2
- data/lib/travel_time/middleware/proto.rb +5 -1
- data/lib/travel_time/response.rb +20 -1
- data/lib/travel_time/transport.rb +1 -1
- data/lib/travel_time/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f41a5c8d37b2b2be35de90168616082a28c31fd759635b1905430e3bd6b6b01
|
|
4
|
+
data.tar.gz: 5aae0fe795498bbbbde3379a3bdb2195e89640c55773ec31eff670b0cf8e5d72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a9f2d1cab48eb5f76d34b20cb77cf76db7f246007263317845d6e6566dae5167f3d63dbf40064e048a2e127ec18fd9115f0943fc8cea0e40bb2f583e4205f61
|
|
7
|
+
data.tar.gz: cf33e330e80a64d3701ca0f9470979146c60f6a08af3480c9fc9cbe92f91478f63a8ec8ff24a61190ad5282e9a0106ecf19a759c2e60e6ac41c228a502cc06c0
|
data/README.md
CHANGED
|
@@ -193,11 +193,17 @@ puts response.body
|
|
|
193
193
|
|
|
194
194
|
### [Isochrones (Time Map) Fast](https://docs.traveltime.com/api/reference/isochrones-fast)
|
|
195
195
|
A very fast version of Isochrone API. However, the request parameters are much more limited.
|
|
196
|
+
Find unions/intersections between different searches.
|
|
197
|
+
|
|
198
|
+
Body attributes:
|
|
199
|
+
* arrival_searches: Searches based on arrival times, split into `one_to_many` and `many_to_one`.
|
|
200
|
+
* unions: Define unions of shapes that are results of previously defined searches.
|
|
201
|
+
* intersections: Define intersections of shapes that are results of previously defined searches.
|
|
196
202
|
|
|
197
203
|
```ruby
|
|
198
204
|
require 'time'
|
|
199
205
|
|
|
200
|
-
|
|
206
|
+
public_transport_search = {
|
|
201
207
|
id: "public transport to Trafalgar Square",
|
|
202
208
|
coords: {
|
|
203
209
|
lat: 51.506756,
|
|
@@ -208,10 +214,33 @@ arrival_search = {
|
|
|
208
214
|
travel_time: 1800,
|
|
209
215
|
}
|
|
210
216
|
|
|
217
|
+
driving_search = {
|
|
218
|
+
id: "driving to Trafalgar Square",
|
|
219
|
+
coords: {
|
|
220
|
+
lat: 51.506756,
|
|
221
|
+
lng: -0.128050
|
|
222
|
+
},
|
|
223
|
+
transportation: { type: "driving" },
|
|
224
|
+
arrival_time_period: 'weekday_morning',
|
|
225
|
+
travel_time: 1800,
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
union = {
|
|
229
|
+
id: 'union of driving and public transport',
|
|
230
|
+
search_ids: ['driving to Trafalgar Square', 'public transport to Trafalgar Square']
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
intersection = {
|
|
234
|
+
id: 'intersection of driving and public transport',
|
|
235
|
+
search_ids: ['driving to Trafalgar Square', 'public transport to Trafalgar Square']
|
|
236
|
+
}
|
|
237
|
+
|
|
211
238
|
response = client.time_map_fast(
|
|
212
239
|
arrival_searches: {
|
|
213
|
-
one_to_many: [
|
|
240
|
+
one_to_many: [public_transport_search, driving_search]
|
|
214
241
|
},
|
|
242
|
+
unions: [union],
|
|
243
|
+
intersections: [intersection]
|
|
215
244
|
)
|
|
216
245
|
|
|
217
246
|
puts response.body
|
|
@@ -878,6 +907,10 @@ If `.proto` files were changed, you can generate Ruby code like this:
|
|
|
878
907
|
```bash
|
|
879
908
|
# For example, if current dir is project root
|
|
880
909
|
protoc --proto_path=lib/travel_time/proto/source --ruby_out=lib lib/travel_time/proto/source/*.proto
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
Use protoc matching the oldest google-protobuf runtime the gemspec allows (protoc v25.x for the 3.25 floor):
|
|
913
|
+
generated code only loads on runtimes from its own major version and the next one.
|
|
881
914
|
|
|
882
915
|
### Release
|
|
883
916
|
|
data/lib/RequestsCommon_pb.rb
CHANGED
|
@@ -1,54 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
2
3
|
# source: RequestsCommon.proto
|
|
3
4
|
|
|
4
5
|
require 'google/protobuf'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n\x14RequestsCommon.proto\x12)com.igeolise.traveltime.rabbitmq.requests\"\"\n\x06\x43oords\x12\x0b\n\x03lat\x18\x01 \x01(\x02\x12\x0b\n\x03lng\x18\x02 \x01(\x02\"\xc6\x02\n\x0eTransportation\x12K\n\x04type\x18\x01 \x01(\x0e\x32=.com.igeolise.traveltime.rabbitmq.requests.TransportationType\x12\\\n\x0fpublicTransport\x18\x02 \x01(\x0b\x32\x41.com.igeolise.traveltime.rabbitmq.requests.PublicTransportDetailsH\x00\x12p\n\x19\x64rivingAndPublicTransport\x18\x03 \x01(\x0b\x32K.com.igeolise.traveltime.rabbitmq.requests.DrivingAndPublicTransportDetailsH\x00\x42\x17\n\x15transportationDetails\"y\n\x16PublicTransportDetails\x12_\n\x14walkingTimeToStation\x18\x01 \x01(\x0b\x32\x41.com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32\"\xbf\x02\n DrivingAndPublicTransportDetails\x12_\n\x14walkingTimeToStation\x18\x01 \x01(\x0b\x32\x41.com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32\x12_\n\x14\x64rivingTimeToStation\x18\x02 \x01(\x0b\x32\x41.com.igeolise.traveltime.rabbitmq.requests.OptionalPositiveUInt32\x12Y\n\x0bparkingTime\x18\x03 \x01(\x0b\x32\x44.com.igeolise.traveltime.rabbitmq.requests.OptionalNonNegativeUInt32\"\'\n\x16OptionalPositiveUInt32\x12\r\n\x05value\x18\x01 \x01(\r\"*\n\x19OptionalNonNegativeUInt32\x12\r\n\x05value\x18\x01 \x01(\r*\xb8\x01\n\x12TransportationType\x12\x14\n\x10PUBLIC_TRANSPORT\x10\x00\x12\x0b\n\x07\x44RIVING\x10\x01\x12 \n\x1c\x44RIVING_AND_PUBLIC_TRANSPORT\x10\x02\x12\x15\n\x11\x44RIVING_AND_FERRY\x10\x03\x12\x0b\n\x07WALKING\x10\x04\x12\x15\n\x11WALKING_AND_FERRY\x10\x07\x12\x0b\n\x07\x43YCLING\x10\x05\x12\x15\n\x11\x43YCLING_AND_FERRY\x10\x06*!\n\nTimePeriod\x12\x13\n\x0fWEEKDAY_MORNING\x10\x00*.\n\x10\x43\x65llPropertyType\x12\x08\n\x04MEAN\x10\x00\x12\x07\n\x03MIN\x10\x01\x12\x07\n\x03MAX\x10\x02\x62\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
pool.add_serialized_file(descriptor_data)
|
|
14
|
+
rescue TypeError
|
|
15
|
+
# Compatibility code: will be removed in the next major version.
|
|
16
|
+
require 'google/protobuf/descriptor_pb'
|
|
17
|
+
parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
|
|
18
|
+
parsed.clear_dependency
|
|
19
|
+
serialized = parsed.class.encode(parsed)
|
|
20
|
+
file = pool.add_serialized_file(serialized)
|
|
21
|
+
warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
|
|
22
|
+
imports = [
|
|
23
|
+
]
|
|
24
|
+
imports.each do |type_name, expected_filename|
|
|
25
|
+
import_file = pool.lookup(type_name).file_descriptor
|
|
26
|
+
if import_file.name != expected_filename
|
|
27
|
+
warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
|
|
50
28
|
end
|
|
51
29
|
end
|
|
30
|
+
warn "Each proto file must use a consistent fully-qualified name."
|
|
31
|
+
warn "This will become an error in the next major version."
|
|
52
32
|
end
|
|
53
33
|
|
|
54
34
|
module Com
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
2
3
|
# source: TimeFilterFastRequest.proto
|
|
3
4
|
|
|
@@ -5,33 +6,32 @@ require 'google/protobuf'
|
|
|
5
6
|
|
|
6
7
|
require 'RequestsCommon_pb'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
add_enum "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property" do
|
|
31
|
-
value :FARES, 0
|
|
32
|
-
value :DISTANCES, 1
|
|
9
|
+
|
|
10
|
+
descriptor_data = "\n\x1bTimeFilterFastRequest.proto\x12)com.igeolise.traveltime.rabbitmq.requests\x1a\x14RequestsCommon.proto\"\x9f\x08\n\x15TimeFilterFastRequest\x12\x64\n\x10oneToManyRequest\x18\x01 \x01(\x0b\x32J.com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany\x12\x64\n\x10manyToOneRequest\x18\x02 \x01(\x0b\x32J.com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.ManyToOne\x1a\x89\x03\n\tOneToMany\x12L\n\x11\x64\x65partureLocation\x18\x01 \x01(\x0b\x32\x31.com.igeolise.traveltime.rabbitmq.requests.Coords\x12\x16\n\x0elocationDeltas\x18\x02 \x03(\x11\x12Q\n\x0etransportation\x18\x03 \x01(\x0b\x32\x39.com.igeolise.traveltime.rabbitmq.requests.Transportation\x12P\n\x11\x61rrivalTimePeriod\x18\x04 \x01(\x0e\x32\x35.com.igeolise.traveltime.rabbitmq.requests.TimePeriod\x12\x12\n\ntravelTime\x18\x05 \x01(\x11\x12]\n\nproperties\x18\x06 \x03(\x0e\x32I.com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property\x1a\x87\x03\n\tManyToOne\x12J\n\x0f\x61rrivalLocation\x18\x01 \x01(\x0b\x32\x31.com.igeolise.traveltime.rabbitmq.requests.Coords\x12\x16\n\x0elocationDeltas\x18\x02 \x03(\x11\x12Q\n\x0etransportation\x18\x03 \x01(\x0b\x32\x39.com.igeolise.traveltime.rabbitmq.requests.Transportation\x12P\n\x11\x61rrivalTimePeriod\x18\x04 \x01(\x0e\x32\x35.com.igeolise.traveltime.rabbitmq.requests.TimePeriod\x12\x12\n\ntravelTime\x18\x05 \x01(\x11\x12]\n\nproperties\x18\x06 \x03(\x0e\x32I.com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property\"$\n\x08Property\x12\t\n\x05\x46\x41RES\x10\x00\x12\r\n\tDISTANCES\x10\x01\x62\x06proto3"
|
|
11
|
+
|
|
12
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
pool.add_serialized_file(descriptor_data)
|
|
16
|
+
rescue TypeError
|
|
17
|
+
# Compatibility code: will be removed in the next major version.
|
|
18
|
+
require 'google/protobuf/descriptor_pb'
|
|
19
|
+
parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
|
|
20
|
+
parsed.clear_dependency
|
|
21
|
+
serialized = parsed.class.encode(parsed)
|
|
22
|
+
file = pool.add_serialized_file(serialized)
|
|
23
|
+
warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
|
|
24
|
+
imports = [
|
|
25
|
+
["com.igeolise.traveltime.rabbitmq.requests.Coords", "RequestsCommon.proto"],
|
|
26
|
+
]
|
|
27
|
+
imports.each do |type_name, expected_filename|
|
|
28
|
+
import_file = pool.lookup(type_name).file_descriptor
|
|
29
|
+
if import_file.name != expected_filename
|
|
30
|
+
warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
|
|
33
31
|
end
|
|
34
32
|
end
|
|
33
|
+
warn "Each proto file must use a consistent fully-qualified name."
|
|
34
|
+
warn "This will become an error in the next major version."
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
module Com
|
|
@@ -1,41 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
2
3
|
# source: TimeFilterFastResponse.proto
|
|
3
4
|
|
|
4
5
|
require 'google/protobuf'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
value :TRAVEL_TIME_LIMIT_TOO_LOW, 6
|
|
28
|
-
value :TRAVEL_TIME_LIMIT_TOO_HIGH, 7
|
|
29
|
-
value :AUTH_ERROR_NO_USER_ID, 8
|
|
30
|
-
value :SERVICE_MISMATCH_WRONG_TRANSPORTATION_MODE, 9
|
|
31
|
-
value :SOURCE_OUT_OF_REACH, 10
|
|
32
|
-
value :INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS, 11
|
|
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
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n\x1cTimeFilterFastResponse.proto\x12*com.igeolise.traveltime.rabbitmq.responses\"\x84\x08\n\x16TimeFilterFastResponse\x12[\n\x05\x65rror\x18\x01 \x01(\x0b\x32H.com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.ErrorB\x02\x18\x01\x12\x61\n\nproperties\x18\x02 \x01(\x0b\x32M.com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Properties\x1aJ\n\nProperties\x12\x13\n\x0btravelTimes\x18\x01 \x03(\x11\x12\x14\n\x0cmonthlyFares\x18\x02 \x03(\x05\x12\x11\n\tdistances\x18\x03 \x03(\x05\x1a\x63\n\x05\x45rror\x12Z\n\x04type\x18\x01 \x01(\x0e\x32L.com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.ErrorType\"\xf8\x04\n\tErrorType\x12\x0f\n\x07UNKNOWN\x10\x00\x1a\x02\x08\x01\x12$\n\x1cONE_TO_MANY_MUST_NOT_BE_NULL\x10\x01\x1a\x02\x08\x01\x12\x1f\n\x17SOURCE_MUST_NOT_BE_NULL\x10\x02\x1a\x02\x08\x01\x12\'\n\x1fTRANSPORTATION_MUST_NOT_BE_NULL\x10\x03\x1a\x02\x08\x01\x12\x1e\n\x16SOURCE_NOT_IN_GEOMETRY\x10\x04\x1a\x02\x08\x01\x12(\n UNRECOGNIZED_TRANSPORTATION_MODE\x10\x05\x1a\x02\x08\x01\x12!\n\x19TRAVEL_TIME_LIMIT_TOO_LOW\x10\x06\x1a\x02\x08\x01\x12\"\n\x1aTRAVEL_TIME_LIMIT_TOO_HIGH\x10\x07\x1a\x02\x08\x01\x12\x1d\n\x15\x41UTH_ERROR_NO_USER_ID\x10\x08\x1a\x02\x08\x01\x12\x32\n*SERVICE_MISMATCH_WRONG_TRANSPORTATION_MODE\x10\t\x1a\x02\x08\x01\x12\x1b\n\x13SOURCE_OUT_OF_REACH\x10\n\x1a\x02\x08\x01\x12\x33\n+INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS\x10\x0b\x1a\x02\x08\x01\x12\'\n\x1f\x44ISTANCE_PROPERTY_NOT_SUPPORTED\x10\x0c\x1a\x02\x08\x01\x12\x37\n/BOTH_MANY_TO_ONE_AND_ONE_TO_MANY_CANNOT_BE_SENT\x10\r\x1a\x02\x08\x01\x12\x33\n+ONE_TO_MANY_OR_MANY_TO_ONE_MUST_NOT_BE_NULL\x10\x0e\x1a\x02\x08\x01\x12\x1d\n\x15INVALID_PROTO_REQUEST\x10\x0f\x1a\x02\x08\x01\x62\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
pool.add_serialized_file(descriptor_data)
|
|
14
|
+
rescue TypeError
|
|
15
|
+
# Compatibility code: will be removed in the next major version.
|
|
16
|
+
require 'google/protobuf/descriptor_pb'
|
|
17
|
+
parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
|
|
18
|
+
parsed.clear_dependency
|
|
19
|
+
serialized = parsed.class.encode(parsed)
|
|
20
|
+
file = pool.add_serialized_file(serialized)
|
|
21
|
+
warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}"
|
|
22
|
+
imports = [
|
|
23
|
+
]
|
|
24
|
+
imports.each do |type_name, expected_filename|
|
|
25
|
+
import_file = pool.lookup(type_name).file_descriptor
|
|
26
|
+
if import_file.name != expected_filename
|
|
27
|
+
warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}"
|
|
37
28
|
end
|
|
38
29
|
end
|
|
30
|
+
warn "Each proto file must use a consistent fully-qualified name."
|
|
31
|
+
warn "This will become an error in the next major version."
|
|
39
32
|
end
|
|
40
33
|
|
|
41
34
|
module Com
|
data/lib/travel_time/client.rb
CHANGED
|
@@ -12,6 +12,7 @@ module TravelTime
|
|
|
12
12
|
extend Limiter::Mixin
|
|
13
13
|
|
|
14
14
|
API_BASE_URL = 'https://api.traveltimeapp.com/v4/'
|
|
15
|
+
PROTO_BASE_URL = 'https://proto.api.traveltimeapp.com/api/v3/'
|
|
15
16
|
|
|
16
17
|
attr_reader :connection, :proto_connection
|
|
17
18
|
|
|
@@ -39,9 +40,9 @@ module TravelTime
|
|
|
39
40
|
|
|
40
41
|
def init_proto_connection
|
|
41
42
|
@proto_connection = Faraday.new do |f|
|
|
42
|
-
f.use TravelTime::Middleware::ProtoMiddleware
|
|
43
43
|
f.response :raise_error if TravelTime.config.raise_on_failure
|
|
44
44
|
f.response :logger if TravelTime.config.enable_logging
|
|
45
|
+
f.use TravelTime::Middleware::ProtoMiddleware
|
|
45
46
|
f.adapter TravelTime.config.http_adapter || Faraday.default_adapter
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -57,7 +58,7 @@ module TravelTime
|
|
|
57
58
|
def perform_request
|
|
58
59
|
unwrap(yield)
|
|
59
60
|
rescue Faraday::Error => e
|
|
60
|
-
raise TravelTime::Error.new(response: Response.from_hash(e.response)) if e.response
|
|
61
|
+
raise TravelTime::Error.new(response: Response.from_hash(e.response), exception: e) if e.response
|
|
61
62
|
|
|
62
63
|
raise TravelTime::Error.new(exception: e)
|
|
63
64
|
rescue StandardError => e
|
|
@@ -66,6 +67,10 @@ module TravelTime
|
|
|
66
67
|
|
|
67
68
|
def perform_request_proto
|
|
68
69
|
unwrap_proto(yield)
|
|
70
|
+
rescue Faraday::Error => e
|
|
71
|
+
raise TravelTime::Error.new(response: Response.from_proto_error(e.response), exception: e) if e.response
|
|
72
|
+
|
|
73
|
+
raise TravelTime::Error.new(exception: e)
|
|
69
74
|
rescue StandardError => e
|
|
70
75
|
raise TravelTime::Error.new(exception: e)
|
|
71
76
|
end
|
|
@@ -120,9 +125,11 @@ module TravelTime
|
|
|
120
125
|
perform_request { connection.post('distance-map', payload, { 'Accept' => format }) }
|
|
121
126
|
end
|
|
122
127
|
|
|
123
|
-
def time_map_fast(arrival_searches:, format: nil)
|
|
128
|
+
def time_map_fast(arrival_searches:, unions: nil, intersections: nil, format: nil)
|
|
124
129
|
payload = {
|
|
125
|
-
arrival_searches: arrival_searches
|
|
130
|
+
arrival_searches: arrival_searches,
|
|
131
|
+
unions: unions,
|
|
132
|
+
intersections: intersections
|
|
126
133
|
}.compact
|
|
127
134
|
perform_request { connection.post('time-map/fast', payload, { 'Accept' => format }) }
|
|
128
135
|
end
|
|
@@ -153,8 +160,7 @@ module TravelTime
|
|
|
153
160
|
properties: properties, request_type: request_type)
|
|
154
161
|
payload = ProtoUtils.encode_proto_message(message)
|
|
155
162
|
perform_request_proto do
|
|
156
|
-
proto_connection.post("
|
|
157
|
-
payload)
|
|
163
|
+
proto_connection.post("#{PROTO_BASE_URL}#{country}/time-filter/fast/#{transport_obj.url_name}", payload)
|
|
158
164
|
end
|
|
159
165
|
end
|
|
160
166
|
|
data/lib/travel_time/error.rb
CHANGED
|
@@ -15,7 +15,7 @@ module TravelTime
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def parse_message(message)
|
|
18
|
-
message || wrapped_exception&.message ||
|
|
18
|
+
message || description || wrapped_exception&.message || DEFAULT_MESSAGE
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def description
|
|
@@ -37,7 +37,8 @@ module TravelTime
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
39
|
def extract_from_body(field)
|
|
40
|
-
response&.body
|
|
40
|
+
body = response&.body
|
|
41
|
+
body[field] if body.is_a?(Hash)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'faraday'
|
|
4
4
|
require 'base64'
|
|
5
|
+
require 'travel_time/error'
|
|
5
6
|
|
|
6
7
|
module TravelTime
|
|
7
8
|
module Middleware
|
|
@@ -9,8 +10,11 @@ module TravelTime
|
|
|
9
10
|
# on each request. These are automatically taken from the `TravelTime.config`.
|
|
10
11
|
class ProtoMiddleware < Faraday::Middleware
|
|
11
12
|
def on_request(env)
|
|
13
|
+
scheme = env.url.scheme
|
|
14
|
+
raise TravelTime::Error, "Refusing to send credentials over #{scheme}" unless scheme == 'https'
|
|
15
|
+
|
|
12
16
|
env.request_headers['Authorization'] =
|
|
13
|
-
"Basic #{Base64.
|
|
17
|
+
"Basic #{Base64.strict_encode64("#{TravelTime.config.application_id}:#{TravelTime.config.api_key}")}"
|
|
14
18
|
env.request_headers['Content-Type'] = 'application/octet-stream'
|
|
15
19
|
env.request_headers['Accept'] = 'application/octet-stream'
|
|
16
20
|
env.request_headers['User-Agent'] = 'Travel Time Ruby SDK'
|
data/lib/travel_time/response.rb
CHANGED
|
@@ -19,7 +19,7 @@ module TravelTime
|
|
|
19
19
|
new(
|
|
20
20
|
status: response.status,
|
|
21
21
|
headers: response.headers,
|
|
22
|
-
body: response.success? ? ProtoUtils.decode_proto_response(response.body) :
|
|
22
|
+
body: response.success? ? ProtoUtils.decode_proto_response(response.body) : proto_error(response.headers)
|
|
23
23
|
)
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -31,6 +31,25 @@ module TravelTime
|
|
|
31
31
|
)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def self.from_proto_error(response)
|
|
35
|
+
new(
|
|
36
|
+
status: response[:status],
|
|
37
|
+
headers: response[:headers],
|
|
38
|
+
body: proto_error(response[:headers])
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Keyed by the fields TravelTime::Error reads from a JSON error body. Header values are always
|
|
43
|
+
# strings, where the JSON API gives an integer error_code and a hash additional_info.
|
|
44
|
+
def self.proto_error(headers)
|
|
45
|
+
{
|
|
46
|
+
'error_code' => headers['X-ERROR-CODE'],
|
|
47
|
+
'description' => headers['X-ERROR-MESSAGE'],
|
|
48
|
+
'additional_info' => headers['X-ERROR-DETAILS']
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
private_class_method :proto_error
|
|
52
|
+
|
|
34
53
|
def initialize(status: nil, headers: nil, body: nil)
|
|
35
54
|
@status = status
|
|
36
55
|
@headers = headers
|
|
@@ -16,7 +16,7 @@ module TravelTime
|
|
|
16
16
|
'driving+pt': { code: 2, url_name: 'pt' },
|
|
17
17
|
driving: { code: 1, url_name: 'driving' },
|
|
18
18
|
walking: { code: 4, url_name: 'walking' },
|
|
19
|
-
cycling: { code: 5, url_name: '
|
|
19
|
+
cycling: { code: 5, url_name: 'cycling' },
|
|
20
20
|
'driving+ferry': { code: 3, url_name: 'driving+ferry' },
|
|
21
21
|
'cycling+ferry': { code: 6, url_name: 'cycling+ferry' },
|
|
22
22
|
'walking+ferry': { code: 7, url_name: 'walking+ferry' }
|
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.
|
|
4
|
+
version: 0.9.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:
|
|
11
|
+
date: 2026-08-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -62,22 +62,22 @@ dependencies:
|
|
|
62
62
|
name: google-protobuf
|
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
|
-
- - "~>"
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: '3.25'
|
|
68
65
|
- - ">="
|
|
69
66
|
- !ruby/object:Gem::Version
|
|
70
67
|
version: 3.25.5
|
|
68
|
+
- - "<"
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '5.0'
|
|
71
71
|
type: :runtime
|
|
72
72
|
prerelease: false
|
|
73
73
|
version_requirements: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements:
|
|
75
|
-
- - "~>"
|
|
76
|
-
- !ruby/object:Gem::Version
|
|
77
|
-
version: '3.25'
|
|
78
75
|
- - ">="
|
|
79
76
|
- !ruby/object:Gem::Version
|
|
80
77
|
version: 3.25.5
|
|
78
|
+
- - "<"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '5.0'
|
|
81
81
|
- !ruby/object:Gem::Dependency
|
|
82
82
|
name: ruby-limiter
|
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|