travel_time 0.3.3 → 0.5.1
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 +106 -0
- data/lib/travel_time/client.rb +51 -2
- data/lib/travel_time/middleware/authentication.rb +2 -0
- data/lib/travel_time/middleware/proto.rb +20 -0
- data/lib/travel_time/proto/source/RequestsCommon.proto +61 -0
- data/lib/travel_time/proto/source/TimeFilterFastRequest.proto +35 -0
- data/lib/travel_time/proto/source/TimeFilterFastResponse.proto +84 -0
- data/lib/travel_time/proto/utils.rb +59 -0
- data/lib/travel_time/proto/v2/RequestsCommon_pb.rb +44 -0
- data/lib/travel_time/proto/v2/TimeFilterFastRequest_pb.rb +40 -0
- data/lib/travel_time/proto/v2/TimeFilterFastResponse_pb.rb +51 -0
- data/lib/travel_time/response.rb +8 -0
- data/lib/travel_time/version.rb +1 -1
- data/lib/travel_time.rb +1 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbf2f0de892f4913899dc12a618af54bdc0d0cd531233407608e9f95962900c8
|
4
|
+
data.tar.gz: d78ae9c592b7c8dbab7c29204f81543cda363dc03928182fe34243e7c5893951
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6eda8e48059030a5f42fce898f444fd9ff93cdf0e0d22357f038ffc65e989fc818fe0adc2d97479ded35bc469fc20d1477c811390ab6e810a91825e270be76
|
7
|
+
data.tar.gz: 57ae66632a19f79ee6f8649551b6f4a397634d60a025c98e047c511e257a0e813fcd77699d9a4fe952b373e2b3d954ca497e05a57a01e346d169854024f7e805
|
data/README.md
CHANGED
@@ -120,6 +120,43 @@ response = client.time_map(
|
|
120
120
|
puts response.body
|
121
121
|
```
|
122
122
|
|
123
|
+
### [Isochrones (Time Map) Fast](https://docs.traveltime.com/api/reference/isochrones-fast)
|
124
|
+
A very fast version of Isochrone API. However, the request parameters are much more limited.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
require 'time'
|
128
|
+
|
129
|
+
arrival_search = {
|
130
|
+
id: "public transport to Trafalgar Square",
|
131
|
+
coords: {
|
132
|
+
lat: 51.506756,
|
133
|
+
lng: -0.128050
|
134
|
+
},
|
135
|
+
transportation: { type: "public_transport" },
|
136
|
+
arrival_time: Time.now.iso8601,
|
137
|
+
travel_time: 1800,
|
138
|
+
}
|
139
|
+
|
140
|
+
union = {
|
141
|
+
id: 'union of driving and public transport',
|
142
|
+
search_ids: ['public transport from Trafalgar Square', 'public transport to Trafalgar Square']
|
143
|
+
}
|
144
|
+
intersection = {
|
145
|
+
id: 'intersection of driving and public transport',
|
146
|
+
search_ids: ['public transport from Trafalgar Square', 'public transport to Trafalgar Square']
|
147
|
+
}
|
148
|
+
|
149
|
+
response = client.time_map_fast(
|
150
|
+
arrival_searches: {
|
151
|
+
one_to_many: [arrival_search]
|
152
|
+
},
|
153
|
+
unions: [union],
|
154
|
+
intersections: [intersection]
|
155
|
+
)
|
156
|
+
|
157
|
+
puts response.body
|
158
|
+
```
|
159
|
+
|
123
160
|
### [Distance Matrix (Time Filter)](https://traveltime.com/docs/api/reference/distance-matrix)
|
124
161
|
Given origin and destination points filter out points that cannot be reached within specified time limit.
|
125
162
|
Find out travel times, distances and costs between an origin and up to 2,000 destination points.
|
@@ -310,6 +347,75 @@ response = client.time_filter_fast(
|
|
310
347
|
puts response.body
|
311
348
|
```
|
312
349
|
|
350
|
+
### [Time Filter (Fast) Proto](https://docs.traveltime.com/api/reference/travel-time-distance-matrix-proto)
|
351
|
+
A fast version of time filter communicating using [protocol buffers](https://github.com/protocolbuffers/protobuf).
|
352
|
+
|
353
|
+
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).
|
354
|
+
|
355
|
+
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.
|
356
|
+
|
357
|
+
Body attributes:
|
358
|
+
* origin: Origin point.
|
359
|
+
* destinations: Destination points. Cannot be more than 200,000.
|
360
|
+
* transport: Transportation type.
|
361
|
+
* travelTime: Time limit;
|
362
|
+
* country: Return the results that are within the specified country
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
origin = {
|
366
|
+
lat: 51.508930,
|
367
|
+
lng: -0.131387,
|
368
|
+
}
|
369
|
+
|
370
|
+
destinations = [{
|
371
|
+
lat: 51.508824,
|
372
|
+
lng: -0.167093,
|
373
|
+
}]
|
374
|
+
|
375
|
+
response = client.time_filter_fast_proto(
|
376
|
+
country: 'UK',
|
377
|
+
origin: origin,
|
378
|
+
destinations: destinations,
|
379
|
+
transport: 'driving+ferry',
|
380
|
+
traveltime: 7200
|
381
|
+
)
|
382
|
+
puts(response.body)
|
383
|
+
```
|
384
|
+
|
385
|
+
### Time Filter (Fast) Proto Distance
|
386
|
+
A version of `Time Filter (Fast) Proto` endpoint that also returns distance information. Request parameters are even more limited than `Time Filter (Fast) Proto`.
|
387
|
+
|
388
|
+
This endpoint is not enabled by default, please [contact us](https://traveltime.com/contact-us) if you wish to obtain access.
|
389
|
+
|
390
|
+
Body attributes:
|
391
|
+
* origin: Origin point.
|
392
|
+
* destinations: Destination points. Cannot be more than 200,000.
|
393
|
+
* transport: Transportation type.
|
394
|
+
* travelTime: Time limit;
|
395
|
+
* country: Return the results that are within the specified country
|
396
|
+
|
397
|
+
```ruby
|
398
|
+
origin = {
|
399
|
+
lat: 51.508930,
|
400
|
+
lng: -0.131387,
|
401
|
+
}
|
402
|
+
|
403
|
+
destinations = [{
|
404
|
+
lat: 51.508824,
|
405
|
+
lng: -0.167093,
|
406
|
+
}]
|
407
|
+
|
408
|
+
response = client.time_filter_fast_proto_distance(
|
409
|
+
country: 'UK',
|
410
|
+
origin: origin,
|
411
|
+
destinations: destinations,
|
412
|
+
transport: 'driving+ferry',
|
413
|
+
traveltime: 7200
|
414
|
+
)
|
415
|
+
puts(response.body)
|
416
|
+
```
|
417
|
+
|
418
|
+
|
313
419
|
### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter)
|
314
420
|
Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts.
|
315
421
|
Currently only supports United Kingdom.
|
data/lib/travel_time/client.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'travel_time/middleware/authentication'
|
5
|
+
require 'travel_time/middleware/proto'
|
5
6
|
|
6
7
|
module TravelTime
|
7
8
|
# The Client class provides the main interface to interact with the TravelTime API
|
8
9
|
class Client # rubocop:disable Metrics/ClassLength
|
9
10
|
API_BASE_URL = 'https://api.traveltimeapp.com/v4/'
|
10
11
|
|
11
|
-
attr_reader :connection
|
12
|
+
attr_reader :connection, :proto_connection
|
12
13
|
|
13
14
|
def initialize
|
14
15
|
@connection = Faraday.new(API_BASE_URL) do |f|
|
@@ -19,12 +20,27 @@ module TravelTime
|
|
19
20
|
f.use TravelTime::Middleware::Authentication
|
20
21
|
f.adapter TravelTime.config.http_adapter || Faraday.default_adapter
|
21
22
|
end
|
23
|
+
|
24
|
+
init_proto_connection
|
25
|
+
end
|
26
|
+
|
27
|
+
def init_proto_connection
|
28
|
+
@proto_connection = Faraday.new do |f|
|
29
|
+
f.use TravelTime::Middleware::ProtoMiddleware
|
30
|
+
f.response :raise_error if TravelTime.config.raise_on_failure
|
31
|
+
f.response :logger if TravelTime.config.enable_logging
|
32
|
+
f.adapter TravelTime.config.http_adapter || Faraday.default_adapter
|
33
|
+
end
|
22
34
|
end
|
23
35
|
|
24
36
|
def unwrap(response)
|
25
37
|
Response.from_object(response)
|
26
38
|
end
|
27
39
|
|
40
|
+
def unwrap_proto(response)
|
41
|
+
Response.from_object_proto(response)
|
42
|
+
end
|
43
|
+
|
28
44
|
def perform_request
|
29
45
|
unwrap(yield)
|
30
46
|
rescue Faraday::Error => e
|
@@ -35,6 +51,12 @@ module TravelTime
|
|
35
51
|
raise TravelTime::Error.new(exception: e)
|
36
52
|
end
|
37
53
|
|
54
|
+
def perform_request_proto
|
55
|
+
unwrap_proto(yield)
|
56
|
+
rescue StandardError => e
|
57
|
+
raise TravelTime::Error.new(exception: e)
|
58
|
+
end
|
59
|
+
|
38
60
|
def map_info
|
39
61
|
perform_request { connection.get('map-info') }
|
40
62
|
end
|
@@ -52,7 +74,7 @@ module TravelTime
|
|
52
74
|
'format.exclude.country': exclude,
|
53
75
|
limit: limit,
|
54
76
|
'force.add.postcode': force_postcode,
|
55
|
-
bounds: bounds
|
77
|
+
bounds: bounds&.join(',')
|
56
78
|
}.compact
|
57
79
|
perform_request { connection.get('geocoding/search', query) }
|
58
80
|
end
|
@@ -77,6 +99,15 @@ module TravelTime
|
|
77
99
|
perform_request { connection.post('time-map', payload, { 'Accept' => format }) }
|
78
100
|
end
|
79
101
|
|
102
|
+
def time_map_fast(arrival_searches:, unions: nil, intersections: nil, format: nil)
|
103
|
+
payload = {
|
104
|
+
arrival_searches: arrival_searches,
|
105
|
+
unions: unions,
|
106
|
+
intersections: intersections
|
107
|
+
}.compact
|
108
|
+
perform_request { connection.post('time-map/fast', payload, { 'Accept' => format }) }
|
109
|
+
end
|
110
|
+
|
80
111
|
def time_filter(locations:, departure_searches: nil, arrival_searches: nil)
|
81
112
|
payload = {
|
82
113
|
locations: locations,
|
@@ -94,6 +125,24 @@ module TravelTime
|
|
94
125
|
perform_request { connection.post('time-filter/fast', payload) }
|
95
126
|
end
|
96
127
|
|
128
|
+
def time_filter_fast_proto(country:, origin:, destinations:, transport:, traveltime:)
|
129
|
+
message = ProtoUtils.make_proto_message(origin, destinations, transport, traveltime)
|
130
|
+
payload = ProtoUtils.encode_proto_message(message)
|
131
|
+
perform_request_proto do
|
132
|
+
proto_connection.post("http://proto.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport}",
|
133
|
+
payload)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def time_filter_fast_proto_distance(country:, origin:, destinations:, transport:, traveltime:)
|
138
|
+
message = ProtoUtils.make_proto_message(origin, destinations, transport, traveltime, properties: [1])
|
139
|
+
payload = ProtoUtils.encode_proto_message(message)
|
140
|
+
perform_request_proto do
|
141
|
+
proto_connection.post("https://proto-with-distance.api.traveltimeapp.com/api/v2/#{country}/time-filter/fast/#{transport}",
|
142
|
+
payload)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
97
146
|
def time_filter_postcodes(departure_searches: nil, arrival_searches: nil)
|
98
147
|
payload = {
|
99
148
|
departure_searches: departure_searches,
|
@@ -9,10 +9,12 @@ module TravelTime
|
|
9
9
|
class Authentication < Faraday::Middleware
|
10
10
|
APP_ID_HEADER = 'X-Application-Id'
|
11
11
|
API_KEY_HEADER = 'X-Api-Key'
|
12
|
+
USER_AGENT = 'User-Agent'
|
12
13
|
|
13
14
|
def on_request(env)
|
14
15
|
env.request_headers[APP_ID_HEADER] = TravelTime.config.application_id
|
15
16
|
env.request_headers[API_KEY_HEADER] = TravelTime.config.api_key
|
17
|
+
env.request_headers[USER_AGENT] = 'Travel Time Ruby SDK'
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module TravelTime
|
7
|
+
module Middleware
|
8
|
+
# The Proto middleware is responsible for setting the basic auth headers for proto requests
|
9
|
+
# on each request. These are automatically taken from the `TravelTime.config`.
|
10
|
+
class ProtoMiddleware < Faraday::Middleware
|
11
|
+
def on_request(env)
|
12
|
+
env.request_headers['Authorization'] =
|
13
|
+
"Basic #{Base64.encode64("#{TravelTime.config.application_id}:#{TravelTime.config.api_key}")}"
|
14
|
+
env.request_headers['Content-Type'] = 'application/octet-stream'
|
15
|
+
env.request_headers['Accept'] = 'application/octet-stream'
|
16
|
+
env.request_headers['User-Agent'] = 'Travel Time Ruby SDK'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package com.igeolise.traveltime.rabbitmq.requests;
|
4
|
+
|
5
|
+
message Coords {
|
6
|
+
float lat = 1;
|
7
|
+
float lng = 2;
|
8
|
+
}
|
9
|
+
|
10
|
+
message Transportation {
|
11
|
+
TransportationType type = 1;
|
12
|
+
}
|
13
|
+
|
14
|
+
enum TransportationType {
|
15
|
+
// Considers all paths found by the following steps:
|
16
|
+
// * up to 30 minutes of walking (always included even if no stops found)
|
17
|
+
// * all connections in the 30 minute walking range from public transport
|
18
|
+
// stops to other public transport stops in travel_time_limit, AND
|
19
|
+
// * up to 30 minutes of walking from public transport stops that were visited
|
20
|
+
// by public transport (IOW a path
|
21
|
+
// [origin]--walking->[stop]--walking-->[destination] is not possible but
|
22
|
+
// [origin]--walking->[stop]--public_transport-->[stop]--walking--> is.
|
23
|
+
PUBLIC_TRANSPORT = 0;
|
24
|
+
// Considers all paths found traveling by car from origin(s) to
|
25
|
+
// destination(s) within the travel_time_limit
|
26
|
+
DRIVING = 1;
|
27
|
+
// Considers all paths found by the following steps:
|
28
|
+
// * up to 30 minutes of driving (always included even no stops found)
|
29
|
+
// * all connections in the 30 minute driving range from public transport stops
|
30
|
+
// to other public transport stops in travel_time_limit, AND
|
31
|
+
// * up to 30 minutes of walking from public transport stops that were visited
|
32
|
+
// by public transport (IOW a path
|
33
|
+
// [origin]--driving->[stop]--walking-->[destination] is not possible but
|
34
|
+
// [origin]--driving->[stop]--public_transport-->[stop]--walking--> is.
|
35
|
+
// AND/OR
|
36
|
+
// * up to 30 minutes of walking
|
37
|
+
//
|
38
|
+
DRIVING_AND_PUBLIC_TRANSPORT = 2;
|
39
|
+
// Considers all paths found travelling by car from origin(s) to
|
40
|
+
// destination(s) including all paths that are traversable by ferries that
|
41
|
+
// take cars within the travel_time_limit.
|
42
|
+
DRIVING_AND_FERRY = 3;
|
43
|
+
// Considers all paths found travelling by foot from origin(s) to
|
44
|
+
// destination(s) within the travel_time_limit
|
45
|
+
WALKING = 4;
|
46
|
+
// Considers all paths found travelling by foot from origin(s) to
|
47
|
+
// destination(s) including all paths that are traversable by ferries that
|
48
|
+
// take passengers within the travel_time_limit
|
49
|
+
WALKING_AND_FERRY = 7;
|
50
|
+
// Considers all paths found travelling by bike from origin(s) to
|
51
|
+
// destination(s) within the travel_time_limit
|
52
|
+
CYCLING = 5;
|
53
|
+
// Considers all paths found travelling by bike from origin(s) to
|
54
|
+
// destination(s) including all paths that are traversable by ferries that
|
55
|
+
// take bikes within the travel_time_limit
|
56
|
+
CYCLING_AND_FERRY = 6;
|
57
|
+
}
|
58
|
+
|
59
|
+
enum TimePeriod {
|
60
|
+
WEEKDAY_MORNING = 0;
|
61
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package com.igeolise.traveltime.rabbitmq.requests;
|
4
|
+
|
5
|
+
import "RequestsCommon.proto";
|
6
|
+
|
7
|
+
message TimeFilterFastRequest {
|
8
|
+
enum Property {
|
9
|
+
FARES = 0;
|
10
|
+
DISTANCES = 1;
|
11
|
+
}
|
12
|
+
message OneToMany {
|
13
|
+
Coords departureLocation = 1;
|
14
|
+
/*
|
15
|
+
* We encode arrival locations as deltas (relative to the source) using a fixedpoint encoding i.e
|
16
|
+
* deltaLat = round((lat - sourceLat) * 10^5).toInt
|
17
|
+
* deltaLon = round((lon - sourceLon) * 10^5).toInt
|
18
|
+
*
|
19
|
+
* The deltas should be interleaved in the `locationDeltas` field i.e
|
20
|
+
*
|
21
|
+
* locationDeltas[0] should be the first lat
|
22
|
+
* locationDeltas[1] should be the first lon
|
23
|
+
* locationDeltas[2] should be the second lat
|
24
|
+
* ...
|
25
|
+
* etc
|
26
|
+
*/
|
27
|
+
repeated sint32 locationDeltas = 2;
|
28
|
+
Transportation transportation = 3;
|
29
|
+
TimePeriod arrivalTimePeriod = 4;
|
30
|
+
sint32 travelTime = 5;
|
31
|
+
repeated Property properties = 6;
|
32
|
+
}
|
33
|
+
|
34
|
+
OneToMany oneToManyRequest = 1;
|
35
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package com.igeolise.traveltime.rabbitmq.responses;
|
4
|
+
|
5
|
+
message TimeFilterFastResponse {
|
6
|
+
message Properties {
|
7
|
+
repeated sint32 travelTimes = 1;
|
8
|
+
repeated int32 monthlyFares = 2;
|
9
|
+
repeated int32 distances = 3;
|
10
|
+
}
|
11
|
+
|
12
|
+
message Error {
|
13
|
+
ErrorType type = 1;
|
14
|
+
}
|
15
|
+
|
16
|
+
enum ErrorType {
|
17
|
+
/*
|
18
|
+
* Catch all unknown error type
|
19
|
+
*/
|
20
|
+
UNKNOWN = 0;
|
21
|
+
/*
|
22
|
+
* oneToManyRequest to many field must not be null
|
23
|
+
*/
|
24
|
+
ONE_TO_MANY_MUST_NOT_BE_NULL = 1;
|
25
|
+
/*
|
26
|
+
* Source (either departure or arrival location) must not be null
|
27
|
+
*/
|
28
|
+
SOURCE_MUST_NOT_BE_NULL = 2;
|
29
|
+
/*
|
30
|
+
* Transportation mode must not be null.
|
31
|
+
*/
|
32
|
+
TRANSPORTATION_MUST_NOT_BE_NULL = 3;
|
33
|
+
/*
|
34
|
+
* Source (either departure or arrival location) must not be null
|
35
|
+
*/
|
36
|
+
SOURCE_NOT_IN_GEOMETRY = 4;
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Transportation mode unrecognized.
|
40
|
+
*/
|
41
|
+
UNRECOGNIZED_TRANSPORTATION_MODE = 5;
|
42
|
+
|
43
|
+
/*
|
44
|
+
* The travel time limit is too low to process this request.
|
45
|
+
*/
|
46
|
+
TRAVEL_TIME_LIMIT_TOO_LOW = 6;
|
47
|
+
|
48
|
+
/*
|
49
|
+
* The travel time limit is too high to process this request.
|
50
|
+
*/
|
51
|
+
TRAVEL_TIME_LIMIT_TOO_HIGH = 7;
|
52
|
+
|
53
|
+
/*
|
54
|
+
* User id not set.
|
55
|
+
*/
|
56
|
+
AUTH_ERROR_NO_USER_ID = 8;
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Message sent to wrong queue - transportation mode cannot be handled.
|
60
|
+
*/
|
61
|
+
SERVICE_MISMATCH_WRONG_TRANSPORTATION_MODE = 9;
|
62
|
+
|
63
|
+
/*
|
64
|
+
* Source is in a area that doesn't have any points that can be out of
|
65
|
+
* search e.g a lake, mountains or other desolate areas.
|
66
|
+
*/
|
67
|
+
SOURCE_OUT_OF_REACH = 10;
|
68
|
+
|
69
|
+
/*
|
70
|
+
* The interleaved deltas array should have (lat/lon) deltas and have an
|
71
|
+
* even number of elements
|
72
|
+
*/
|
73
|
+
INTERLEAVED_DELTAS_INVALID_COORDINATE_PAIRS = 11;
|
74
|
+
|
75
|
+
/*
|
76
|
+
* Public transport requests do not support returning distances for
|
77
|
+
* returned points.
|
78
|
+
*/
|
79
|
+
DISTANCE_PROPERTY_NOT_SUPPORTED = 12;
|
80
|
+
}
|
81
|
+
|
82
|
+
Error error = 1;
|
83
|
+
Properties properties = 2;
|
84
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
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'
|
6
|
+
|
7
|
+
module TravelTime
|
8
|
+
# Utilities for encoding/decoding protobuf requests
|
9
|
+
class ProtoUtils
|
10
|
+
def self.encode_fixed_point(source, target)
|
11
|
+
((target - source) * 10.pow(5)).round
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.build_deltas(departure, destinations)
|
15
|
+
deltas = destinations.map do |destination|
|
16
|
+
[encode_fixed_point(departure[:lat], destination[:lat]),
|
17
|
+
encode_fixed_point(departure[:lng], destination[:lng])]
|
18
|
+
end
|
19
|
+
deltas.flatten
|
20
|
+
end
|
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)
|
33
|
+
Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::OneToMany.new(
|
34
|
+
departureLocation: origin,
|
35
|
+
locationDeltas: build_deltas(origin, destinations),
|
36
|
+
transportation: Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new(
|
37
|
+
{ type: get_proto_transport_code(transport) }
|
38
|
+
),
|
39
|
+
arrivalTimePeriod: 0,
|
40
|
+
travelTime: traveltime,
|
41
|
+
properties: properties
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.make_proto_message(origin, destinations, transport, traveltime, properties: nil)
|
46
|
+
Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new(
|
47
|
+
oneToManyRequest: make_one_to_many(origin, destinations, transport, traveltime, properties)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.encode_proto_message(message)
|
52
|
+
Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.encode(message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.decode_proto_response(response)
|
56
|
+
Com::Igeolise::Traveltime::Rabbitmq::Responses::TimeFilterFastResponse.decode(response).to_h
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: TimeFilterFastRequest.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require_relative 'RequestsCommon_pb'
|
7
|
+
|
8
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
+
add_file("TimeFilterFastRequest.proto", :syntax => :proto3) do
|
10
|
+
add_message "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest" do
|
11
|
+
optional :oneToManyRequest, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany"
|
12
|
+
end
|
13
|
+
add_message "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany" do
|
14
|
+
optional :departureLocation, :message, 1, "com.igeolise.traveltime.rabbitmq.requests.Coords"
|
15
|
+
repeated :locationDeltas, :sint32, 2
|
16
|
+
optional :transportation, :message, 3, "com.igeolise.traveltime.rabbitmq.requests.Transportation"
|
17
|
+
optional :arrivalTimePeriod, :enum, 4, "com.igeolise.traveltime.rabbitmq.requests.TimePeriod"
|
18
|
+
optional :travelTime, :sint32, 5
|
19
|
+
repeated :properties, :enum, 6, "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property"
|
20
|
+
end
|
21
|
+
add_enum "com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property" do
|
22
|
+
value :FARES, 0
|
23
|
+
value :DISTANCES, 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Com
|
29
|
+
module Igeolise
|
30
|
+
module Traveltime
|
31
|
+
module Rabbitmq
|
32
|
+
module Requests
|
33
|
+
TimeFilterFastRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest").msgclass
|
34
|
+
TimeFilterFastRequest::OneToMany = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.OneToMany").msgclass
|
35
|
+
TimeFilterFastRequest::Property = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.requests.TimeFilterFastRequest.Property").enummodule
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: TimeFilterFastResponse.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("TimeFilterFastResponse.proto", :syntax => :proto3) do
|
8
|
+
add_message "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse" do
|
9
|
+
optional :error, :message, 1, "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Error"
|
10
|
+
optional :properties, :message, 2, "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Properties"
|
11
|
+
end
|
12
|
+
add_message "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Properties" do
|
13
|
+
repeated :travelTimes, :sint32, 1
|
14
|
+
repeated :monthlyFares, :int32, 2
|
15
|
+
repeated :distances, :int32, 3
|
16
|
+
end
|
17
|
+
add_message "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Error" do
|
18
|
+
optional :type, :enum, 1, "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.ErrorType"
|
19
|
+
end
|
20
|
+
add_enum "com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.ErrorType" do
|
21
|
+
value :UNKNOWN, 0
|
22
|
+
value :ONE_TO_MANY_MUST_NOT_BE_NULL, 1
|
23
|
+
value :SOURCE_MUST_NOT_BE_NULL, 2
|
24
|
+
value :TRANSPORTATION_MUST_NOT_BE_NULL, 3
|
25
|
+
value :SOURCE_NOT_IN_GEOMETRY, 4
|
26
|
+
value :UNRECOGNIZED_TRANSPORTATION_MODE, 5
|
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
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Com
|
39
|
+
module Igeolise
|
40
|
+
module Traveltime
|
41
|
+
module Rabbitmq
|
42
|
+
module Responses
|
43
|
+
TimeFilterFastResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse").msgclass
|
44
|
+
TimeFilterFastResponse::Properties = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Properties").msgclass
|
45
|
+
TimeFilterFastResponse::Error = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.Error").msgclass
|
46
|
+
TimeFilterFastResponse::ErrorType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("com.igeolise.traveltime.rabbitmq.responses.TimeFilterFastResponse.ErrorType").enummodule
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/travel_time/response.rb
CHANGED
@@ -15,6 +15,14 @@ module TravelTime
|
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.from_object_proto(response)
|
19
|
+
new(
|
20
|
+
status: response.status,
|
21
|
+
headers: response.headers,
|
22
|
+
body: ProtoUtils.decode_proto_response(response.body)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.from_hash(response)
|
19
27
|
new(
|
20
28
|
status: response[:status],
|
data/lib/travel_time/version.rb
CHANGED
data/lib/travel_time.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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TravelTime Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -44,6 +44,26 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: google-protobuf
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.21'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.21.9
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.21'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.21.9
|
47
67
|
description: TravelTime SDK for Ruby programming language
|
48
68
|
email:
|
49
69
|
- support@traveltime.com
|
@@ -61,6 +81,14 @@ files:
|
|
61
81
|
- lib/travel_time/client.rb
|
62
82
|
- lib/travel_time/error.rb
|
63
83
|
- lib/travel_time/middleware/authentication.rb
|
84
|
+
- lib/travel_time/middleware/proto.rb
|
85
|
+
- lib/travel_time/proto/source/RequestsCommon.proto
|
86
|
+
- lib/travel_time/proto/source/TimeFilterFastRequest.proto
|
87
|
+
- lib/travel_time/proto/source/TimeFilterFastResponse.proto
|
88
|
+
- lib/travel_time/proto/utils.rb
|
89
|
+
- lib/travel_time/proto/v2/RequestsCommon_pb.rb
|
90
|
+
- lib/travel_time/proto/v2/TimeFilterFastRequest_pb.rb
|
91
|
+
- lib/travel_time/proto/v2/TimeFilterFastResponse_pb.rb
|
64
92
|
- lib/travel_time/response.rb
|
65
93
|
- lib/travel_time/version.rb
|
66
94
|
homepage: https://traveltime.com
|