travel_time 0.4.0 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -42
- data/lib/travel_time/client.rb +14 -9
- data/lib/travel_time/middleware/authentication.rb +2 -0
- data/lib/travel_time/middleware/proto.rb +1 -0
- data/lib/travel_time/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 479666f568d16431cf279ead2c1bf61c7f8e1f29596970afbd255750bf808f12
|
4
|
+
data.tar.gz: 0a83062eebe1621bb576ca3629e35f13c42f4e4ce0145f08d42ff12cce78e224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587e2360688195fa2caebf53530bd6c8ca0969e757c1f9c9c071903c7ef8f0106f7225915c9e1c0a8c947fbc6d40ac291f30ad1862ed52b8adf5b200cc36c349
|
7
|
+
data.tar.gz: 1893e32110aeda9fbea6bec890d59b5f0c3ffeacd38bb9a0bb6668894761a3dce2d9a651b3f8f6afb88e9202bb10ed460518a31004e4c3dca618e7b1fe0a0ada
|
data/README.md
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/travel_time.svg)](https://rubygems.org/gems/travel_time)
|
4
4
|
[![GitHub Actions CI](https://github.com/traveltime-dev/traveltime-sdk-ruby/workflows/CI/badge.svg)](https://github.com/traveltime-dev/traveltime-sdk-ruby/actions?query=workflow%3ACI)
|
5
5
|
|
6
|
-
|
7
|
-
This open-source library allows you to access [TravelTime API](https://docs.traveltime.com/overview/introduction)
|
8
|
-
endpoints.
|
6
|
+
[Travel Time](https://docs.traveltime.com/api/overview/introduction) Ruby SDK helps users find locations by journey time rather than using ‘as the crow flies’ distance. Time-based searching gives users more opportunities for personalisation and delivers a more relevant search.
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -30,7 +28,7 @@ In order to be able to call the API, you'll first need to set your Application I
|
|
30
28
|
```ruby
|
31
29
|
TravelTime.configure do |config|
|
32
30
|
config.application_id = '<your app id>'
|
33
|
-
config.api_key = '<your
|
31
|
+
config.api_key = '<your app key>'
|
34
32
|
end
|
35
33
|
```
|
36
34
|
|
@@ -70,11 +68,16 @@ departure_search = {
|
|
70
68
|
client.time_map(departure_searches: [departure_search])
|
71
69
|
```
|
72
70
|
|
73
|
-
|
74
71
|
### [Isochrones (Time Map)](https://traveltime.com/docs/api/reference/isochrones)
|
75
72
|
Given origin coordinates, find shapes of zones reachable within corresponding travel time.
|
76
73
|
Find unions/intersections between different searches.
|
77
74
|
|
75
|
+
Body attributes:
|
76
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches.
|
77
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches.
|
78
|
+
* unions: Define unions of shapes that are results of previously defined searches.
|
79
|
+
* intersections: Define intersections of shapes that are results of previously defined searches.
|
80
|
+
|
78
81
|
```ruby
|
79
82
|
require 'time'
|
80
83
|
|
@@ -120,10 +123,41 @@ response = client.time_map(
|
|
120
123
|
puts response.body
|
121
124
|
```
|
122
125
|
|
126
|
+
### [Isochrones (Time Map) Fast](https://docs.traveltime.com/api/reference/isochrones-fast)
|
127
|
+
A very fast version of Isochrone API. However, the request parameters are much more limited.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
require 'time'
|
131
|
+
|
132
|
+
arrival_search = {
|
133
|
+
id: "public transport to Trafalgar Square",
|
134
|
+
coords: {
|
135
|
+
lat: 51.506756,
|
136
|
+
lng: -0.128050
|
137
|
+
},
|
138
|
+
transportation: { type: "public_transport" },
|
139
|
+
arrival_time_period: 'weekday_morning',
|
140
|
+
travel_time: 1800,
|
141
|
+
}
|
142
|
+
|
143
|
+
response = client.time_map_fast(
|
144
|
+
arrival_searches: {
|
145
|
+
one_to_many: [arrival_search]
|
146
|
+
},
|
147
|
+
)
|
148
|
+
|
149
|
+
puts response.body
|
150
|
+
```
|
151
|
+
|
123
152
|
### [Distance Matrix (Time Filter)](https://traveltime.com/docs/api/reference/distance-matrix)
|
124
153
|
Given origin and destination points filter out points that cannot be reached within specified time limit.
|
125
154
|
Find out travel times, distances and costs between an origin and up to 2,000 destination points.
|
126
155
|
|
156
|
+
Body attributes:
|
157
|
+
* locations: Locations to use. Each location requires an id and lat/lng values
|
158
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches
|
159
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches
|
160
|
+
|
127
161
|
```ruby
|
128
162
|
require 'time'
|
129
163
|
|
@@ -184,6 +218,11 @@ puts response.body
|
|
184
218
|
### [Routes](https://traveltime.com/docs/api/reference/routes)
|
185
219
|
Returns routing information between source and destinations.
|
186
220
|
|
221
|
+
Body attributes:
|
222
|
+
* locations: Locations to use. Each location requires an id and lat/lng values.
|
223
|
+
* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches.
|
224
|
+
* arrival_searches: Searches based on arrival times. Arrive at destination location at no later than given time. You can define a maximum of 10 searches.
|
225
|
+
|
187
226
|
```ruby
|
188
227
|
require 'time'
|
189
228
|
|
@@ -248,7 +287,7 @@ puts response.body
|
|
248
287
|
```
|
249
288
|
|
250
289
|
### [Time Filter (Fast)](https://traveltime.com/docs/api/reference/time-filter-fast)
|
251
|
-
A very fast version of time_filter()
|
290
|
+
A very fast version of `time_filter()`.
|
252
291
|
However, the request parameters are much more limited.
|
253
292
|
Currently only supports UK and Ireland.
|
254
293
|
|
@@ -310,7 +349,7 @@ response = client.time_filter_fast(
|
|
310
349
|
puts response.body
|
311
350
|
```
|
312
351
|
|
313
|
-
### [Time Filter
|
352
|
+
### [Time Filter Fast (Proto)](https://docs.traveltime.com/api/reference/travel-time-distance-matrix-proto)
|
314
353
|
A fast version of time filter communicating using [protocol buffers](https://github.com/protocolbuffers/protobuf).
|
315
354
|
|
316
355
|
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).
|
@@ -320,9 +359,9 @@ This inflexibility comes with a benefit of faster response times (Over 5x faster
|
|
320
359
|
Body attributes:
|
321
360
|
* origin: Origin point.
|
322
361
|
* destinations: Destination points. Cannot be more than 200,000.
|
362
|
+
* country: Return the results that are within the specified country.
|
323
363
|
* transport: Transportation type.
|
324
|
-
*
|
325
|
-
* country: Return the results that are within the specified country
|
364
|
+
* traveltime: Time limit.
|
326
365
|
|
327
366
|
```ruby
|
328
367
|
origin = {
|
@@ -345,39 +384,7 @@ response = client.time_filter_fast_proto(
|
|
345
384
|
puts(response.body)
|
346
385
|
```
|
347
386
|
|
348
|
-
|
349
|
-
A version of `Time Filter (Fast) Proto` endpoint that also returns distance information. Request parameters are even more limited than `Time Filter (Fast) Proto`.
|
350
|
-
|
351
|
-
This endpoint is not enabled by default, please [contact us](https://traveltime.com/contact-us) if you wish to obtain access.
|
352
|
-
|
353
|
-
Body attributes:
|
354
|
-
* origin: Origin point.
|
355
|
-
* destinations: Destination points. Cannot be more than 200,000.
|
356
|
-
* transport: Transportation type.
|
357
|
-
* travelTime: Time limit;
|
358
|
-
* country: Return the results that are within the specified country
|
359
|
-
|
360
|
-
```ruby
|
361
|
-
origin = {
|
362
|
-
lat: 51.508930,
|
363
|
-
lng: -0.131387,
|
364
|
-
}
|
365
|
-
|
366
|
-
destinations = [{
|
367
|
-
lat: 51.508824,
|
368
|
-
lng: -0.167093,
|
369
|
-
}]
|
370
|
-
|
371
|
-
response = client.time_filter_fast_proto_distance(
|
372
|
-
country: 'UK',
|
373
|
-
origin: origin,
|
374
|
-
destinations: destinations,
|
375
|
-
transport: 'driving+ferry',
|
376
|
-
traveltime: 7200
|
377
|
-
)
|
378
|
-
puts(response.body)
|
379
|
-
```
|
380
|
-
|
387
|
+
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.
|
381
388
|
|
382
389
|
### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter)
|
383
390
|
Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts.
|
data/lib/travel_time/client.rb
CHANGED
@@ -66,27 +66,25 @@ module TravelTime
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def geocoding(query:, within_country: nil, format_name: nil, exclude: nil, limit: nil, force_postcode: nil,
|
69
|
-
bounds: nil)
|
69
|
+
bounds: nil, accept_language: nil)
|
70
70
|
query = {
|
71
71
|
query: query,
|
72
|
-
'within.country': within_country,
|
72
|
+
'within.country': within_country.is_a?(Array) ? within_country.join(',') : within_country,
|
73
73
|
'format.name': format_name,
|
74
74
|
'format.exclude.country': exclude,
|
75
75
|
limit: limit,
|
76
76
|
'force.add.postcode': force_postcode,
|
77
|
-
bounds: bounds
|
77
|
+
bounds: bounds&.join(',')
|
78
78
|
}.compact
|
79
|
-
perform_request { connection.get('geocoding/search', query) }
|
79
|
+
perform_request { connection.get('geocoding/search', query, { 'Accept-Language' => accept_language }) }
|
80
80
|
end
|
81
81
|
|
82
|
-
def reverse_geocoding(lat:, lng:,
|
82
|
+
def reverse_geocoding(lat:, lng:, accept_language: nil)
|
83
83
|
query = {
|
84
84
|
lat: lat,
|
85
|
-
lng: lng
|
86
|
-
'within.country': within_country,
|
87
|
-
'exclude.location.types': exclude
|
85
|
+
lng: lng
|
88
86
|
}.compact
|
89
|
-
perform_request { connection.get('geocoding/reverse', query) }
|
87
|
+
perform_request { connection.get('geocoding/reverse', query, { 'Accept-Language' => accept_language }) }
|
90
88
|
end
|
91
89
|
|
92
90
|
def time_map(departure_searches: nil, arrival_searches: nil, unions: nil, intersections: nil, format: nil)
|
@@ -99,6 +97,13 @@ module TravelTime
|
|
99
97
|
perform_request { connection.post('time-map', payload, { 'Accept' => format }) }
|
100
98
|
end
|
101
99
|
|
100
|
+
def time_map_fast(arrival_searches:, format: nil)
|
101
|
+
payload = {
|
102
|
+
arrival_searches: arrival_searches
|
103
|
+
}.compact
|
104
|
+
perform_request { connection.post('time-map/fast', payload, { 'Accept' => format }) }
|
105
|
+
end
|
106
|
+
|
102
107
|
def time_filter(locations:, departure_searches: nil, arrival_searches: nil)
|
103
108
|
payload = {
|
104
109
|
locations: locations,
|
@@ -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
|
@@ -13,6 +13,7 @@ module TravelTime
|
|
13
13
|
"Basic #{Base64.encode64("#{TravelTime.config.application_id}:#{TravelTime.config.api_key}")}"
|
14
14
|
env.request_headers['Content-Type'] = 'application/octet-stream'
|
15
15
|
env.request_headers['Accept'] = 'application/octet-stream'
|
16
|
+
env.request_headers['User-Agent'] = 'Travel Time Ruby SDK'
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
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
|
4
|
+
version: 0.5.4
|
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: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|