travel_time 0.5.4 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 479666f568d16431cf279ead2c1bf61c7f8e1f29596970afbd255750bf808f12
4
- data.tar.gz: 0a83062eebe1621bb576ca3629e35f13c42f4e4ce0145f08d42ff12cce78e224
3
+ metadata.gz: 3d61024c00091bdbbf0036dcb0f0b3cbc13dfdf0f0690aa847cd2720ba9d7866
4
+ data.tar.gz: b7eb9f385d345cb2d115e34a37b85e6128730f3b87ca6ee6f34e79988b93236d
5
5
  SHA512:
6
- metadata.gz: 587e2360688195fa2caebf53530bd6c8ca0969e757c1f9c9c071903c7ef8f0106f7225915c9e1c0a8c947fbc6d40ac291f30ad1862ed52b8adf5b200cc36c349
7
- data.tar.gz: 1893e32110aeda9fbea6bec890d59b5f0c3ffeacd38bb9a0bb6668894761a3dce2d9a651b3f8f6afb88e9202bb10ed460518a31004e4c3dca618e7b1fe0a0ada
6
+ metadata.gz: 16b1444ca180d2a151794b3eacc38d7f88b7873cb1c7c83446d53e19bee5b7b9ce4bf502075fd8f9215489a8132d6296288ecbe85e14ffad48f74ac10e3cd999
7
+ data.tar.gz: 9f670c473b8536204514f9f638e4cd654eeab197224f46c0a91552a6852d6a9ff35dcdf620220f07b7afbd915ac536c60a5fcfa87ebe45c657ad1f38323e56dd
data/README.md CHANGED
@@ -68,6 +68,14 @@ departure_search = {
68
68
  client.time_map(departure_searches: [departure_search])
69
69
  ```
70
70
 
71
+ ### Rate Limiting
72
+
73
+ You may specify an optional rate limit when initializing your client. The `rate_limit` parameter sets a cap on the number of requests that can be made to the API in 60 seconds. Requests are balanced at equal intervals.
74
+
75
+ ```ruby
76
+ client = TravelTime::Client.new(rate_limit = 60)
77
+ ```
78
+
71
79
  ### [Isochrones (Time Map)](https://traveltime.com/docs/api/reference/isochrones)
72
80
  Given origin coordinates, find shapes of zones reachable within corresponding travel time.
73
81
  Find unions/intersections between different searches.
@@ -215,77 +223,6 @@ response = client.time_filter(
215
223
  puts response.body
216
224
  ```
217
225
 
218
- ### [Routes](https://traveltime.com/docs/api/reference/routes)
219
- Returns routing information between source and destinations.
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
-
226
- ```ruby
227
- require 'time'
228
-
229
- locations = [{
230
- id: 'London center',
231
- coords: {
232
- lat: 51.508930,
233
- lng: -0.131387
234
- }
235
- },
236
- {
237
- id: 'Hyde Park',
238
- coords: {
239
- lat: 51.508824,
240
- lng: -0.167093
241
- }
242
- },
243
- {
244
- id: 'ZSL London Zoo',
245
- coords: {
246
- lat: 51.536067,
247
- lng: -0.153596
248
- }
249
- }]
250
-
251
- departure_search = {
252
- id: 'forward search example',
253
- departure_location_id: 'London center',
254
- arrival_location_ids: ['Hyde Park', 'ZSL London Zoo'],
255
- transportation: {
256
- type: 'bus'
257
- },
258
- departure_time: Time.now.iso8601,
259
- travel_time: 1800,
260
- properties: ['travel_time'],
261
- range: {
262
- enabled: true,
263
- max_results: 3,
264
- width: 600
265
- }
266
- }
267
-
268
- arrival_search = {
269
- id: 'backward search example',
270
- departure_location_ids: ['Hyde Park', 'ZSL London Zoo'],
271
- arrival_location_id: 'London center',
272
- transportation: {
273
- type: 'public_transport'
274
- },
275
- arrival_time: Time.now.iso8601,
276
- travel_time: 1800,
277
- properties: ['travel_time', 'distance', 'fares', 'route']
278
- }
279
-
280
- response = client.routes(
281
- locations: locations,
282
- departure_searches: [departure_search],
283
- arrival_searches: [arrival_search]
284
- )
285
-
286
- puts response.body
287
- ```
288
-
289
226
  ### [Time Filter (Fast)](https://traveltime.com/docs/api/reference/time-filter-fast)
290
227
  A very fast version of `time_filter()`.
291
228
  However, the request parameters are much more limited.
@@ -386,8 +323,95 @@ puts(response.body)
386
323
 
387
324
  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.
388
325
 
389
- ### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter)
390
- Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts.
326
+ ### [Routes](https://traveltime.com/docs/api/reference/routes)
327
+ Returns routing information between source and destinations.
328
+
329
+ Body attributes:
330
+ * locations: Locations to use. Each location requires an id and lat/lng values.
331
+ * departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches.
332
+ * 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.
333
+
334
+ ```ruby
335
+ require 'time'
336
+
337
+ locations = [{
338
+ id: 'London center',
339
+ coords: {
340
+ lat: 51.508930,
341
+ lng: -0.131387
342
+ }
343
+ },
344
+ {
345
+ id: 'Hyde Park',
346
+ coords: {
347
+ lat: 51.508824,
348
+ lng: -0.167093
349
+ }
350
+ },
351
+ {
352
+ id: 'ZSL London Zoo',
353
+ coords: {
354
+ lat: 51.536067,
355
+ lng: -0.153596
356
+ }
357
+ }]
358
+
359
+ departure_search = {
360
+ id: 'forward search example',
361
+ departure_location_id: 'London center',
362
+ arrival_location_ids: ['Hyde Park', 'ZSL London Zoo'],
363
+ transportation: {
364
+ type: 'bus'
365
+ },
366
+ departure_time: Time.now.iso8601,
367
+ travel_time: 1800,
368
+ properties: ['travel_time'],
369
+ range: {
370
+ enabled: true,
371
+ max_results: 3,
372
+ width: 600
373
+ }
374
+ }
375
+
376
+ arrival_search = {
377
+ id: 'backward search example',
378
+ departure_location_ids: ['Hyde Park', 'ZSL London Zoo'],
379
+ arrival_location_id: 'London center',
380
+ transportation: {
381
+ type: 'public_transport'
382
+ },
383
+ arrival_time: Time.now.iso8601,
384
+ travel_time: 1800,
385
+ properties: ['travel_time', 'distance', 'fares', 'route']
386
+ }
387
+
388
+ response = client.routes(
389
+ locations: locations,
390
+ departure_searches: [departure_search],
391
+ arrival_searches: [arrival_search]
392
+ )
393
+
394
+ puts response.body
395
+ ```
396
+
397
+ ### [Geocoding (Search)](https://traveltime.com/docs/api/reference/geocoding-search)
398
+ Match a query string to geographic coordinates.
399
+
400
+ ```ruby
401
+ response = client.geocoding(query: 'London', within_country: 'GB')
402
+ puts response.body
403
+ ```
404
+
405
+ ### [Reverse Geocoding](https://traveltime.com/docs/api/reference/geocoding-reverse)
406
+ Attempt to match a latitude, longitude pair to an address.
407
+
408
+ ```ruby
409
+ response = client.reverse_geocoding(lat: 51.506756, lng: -0.128050)
410
+ puts response.body
411
+ ```
412
+
413
+ ### [Time Filter (Postcodes)](https://traveltime.com/docs/api/reference/postcode-search)
414
+ Find reachable postcodes from origin (or to destination) and get statistics about such postcodes.
391
415
  Currently only supports United Kingdom.
392
416
 
393
417
  ```ruby
@@ -399,8 +423,7 @@ departure_search = {
399
423
  travel_time: 1800,
400
424
  coords: { lat: 51.507609, lng: -0.128315 },
401
425
  transportation: { type: 'public_transport' },
402
- properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
403
- reachable_postcodes_threshold: 0.1
426
+ properties: ['travel_time', 'distance']
404
427
  }
405
428
 
406
429
  arrival_search = {
@@ -409,20 +432,19 @@ arrival_search = {
409
432
  travel_time: 1800,
410
433
  coords: { lat: 51.507609, lng: -0.128315 },
411
434
  transportation: { type: 'public_transport' },
412
- properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
413
- reachable_postcodes_threshold: 0.1
435
+ properties: ['travel_time', 'distance']
414
436
  }
415
437
 
416
- response = client.time_filter_postcode_districts(
417
- departure_searches: [departure_search],
438
+ response = client.time_filter_postcodes(
439
+ departure_searches: [departure_search],
418
440
  arrival_searches: [arrival_search]
419
441
  )
420
442
 
421
443
  puts response.body
422
444
  ```
423
445
 
424
- ### [Time Filter (Postcode Sectors)](https://traveltime.com/docs/api/reference/postcode-sector-filter)
425
- Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors.
446
+ ### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter)
447
+ Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts.
426
448
  Currently only supports United Kingdom.
427
449
 
428
450
  ```ruby
@@ -448,7 +470,7 @@ arrival_search = {
448
470
  reachable_postcodes_threshold: 0.1
449
471
  }
450
472
 
451
- response = client.time_filter_postcode_sectors(
473
+ response = client.time_filter_postcode_districts(
452
474
  departure_searches: [departure_search],
453
475
  arrival_searches: [arrival_search]
454
476
  )
@@ -456,8 +478,8 @@ response = client.time_filter_postcode_sectors(
456
478
  puts response.body
457
479
  ```
458
480
 
459
- ### [Time Filter (Postcodes)](https://traveltime.com/docs/api/reference/postcode-search)
460
- Find reachable postcodes from origin (or to destination) and get statistics about such postcodes.
481
+ ### [Time Filter (Postcode Sectors)](https://traveltime.com/docs/api/reference/postcode-sector-filter)
482
+ Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors.
461
483
  Currently only supports United Kingdom.
462
484
 
463
485
  ```ruby
@@ -469,7 +491,8 @@ departure_search = {
469
491
  travel_time: 1800,
470
492
  coords: { lat: 51.507609, lng: -0.128315 },
471
493
  transportation: { type: 'public_transport' },
472
- properties: ['travel_time', 'distance']
494
+ properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
495
+ reachable_postcodes_threshold: 0.1
473
496
  }
474
497
 
475
498
  arrival_search = {
@@ -478,33 +501,18 @@ arrival_search = {
478
501
  travel_time: 1800,
479
502
  coords: { lat: 51.507609, lng: -0.128315 },
480
503
  transportation: { type: 'public_transport' },
481
- properties: ['travel_time', 'distance']
504
+ properties: ['coverage', 'travel_time_reachable', 'travel_time_all'],
505
+ reachable_postcodes_threshold: 0.1
482
506
  }
483
507
 
484
- response = client.time_filter_postcodes(
485
- departure_searches: [departure_search],
508
+ response = client.time_filter_postcode_sectors(
509
+ departure_searches: [departure_search],
486
510
  arrival_searches: [arrival_search]
487
511
  )
488
512
 
489
513
  puts response.body
490
514
  ```
491
515
 
492
- ### [Geocoding (Search)](https://traveltime.com/docs/api/reference/geocoding-search)
493
- Match a query string to geographic coordinates.
494
-
495
- ```ruby
496
- response = client.geocoding(query: 'London', within_country: 'GB')
497
- puts response.body
498
- ```
499
-
500
- ### [Reverse Geocoding](https://traveltime.com/docs/api/reference/geocoding-reverse)
501
- Attempt to match a latitude, longitude pair to an address.
502
-
503
- ```ruby
504
- response = client.reverse_geocoding(lat: 51.506756, lng: -0.128050)
505
- puts response.body
506
- ```
507
-
508
516
  ### [Map Info](https://traveltime.com/docs/api/reference/map-info)
509
517
  Get information about currently supported countries.
510
518
 
@@ -3,15 +3,28 @@
3
3
  require 'faraday'
4
4
  require 'travel_time/middleware/authentication'
5
5
  require 'travel_time/middleware/proto'
6
+ require 'limiter'
6
7
 
7
8
  module TravelTime
8
9
  # The Client class provides the main interface to interact with the TravelTime API
9
10
  class Client # rubocop:disable Metrics/ClassLength
11
+ extend Limiter::Mixin
10
12
  API_BASE_URL = 'https://api.traveltimeapp.com/v4/'
11
13
 
12
14
  attr_reader :connection, :proto_connection
13
15
 
14
- def initialize
16
+ def initialize(rate_limit = nil)
17
+ init_connection
18
+ init_proto_connection
19
+
20
+ return unless rate_limit
21
+
22
+ %i[perform_request perform_request_proto].each do |method_name|
23
+ self.class.limit_method method_name, balanced: true, rate: rate_limit
24
+ end
25
+ end
26
+
27
+ def init_connection
15
28
  @connection = Faraday.new(API_BASE_URL) do |f|
16
29
  f.request :json
17
30
  f.response :raise_error if TravelTime.config.raise_on_failure
@@ -20,8 +33,6 @@ module TravelTime
20
33
  f.use TravelTime::Middleware::Authentication
21
34
  f.adapter TravelTime.config.http_adapter || Faraday.default_adapter
22
35
  end
23
-
24
- init_proto_connection
25
36
  end
26
37
 
27
38
  def init_proto_connection
@@ -14,7 +14,7 @@ module TravelTime
14
14
  def on_request(env)
15
15
  env.request_headers[APP_ID_HEADER] = TravelTime.config.application_id
16
16
  env.request_headers[API_KEY_HEADER] = TravelTime.config.api_key
17
- env.request_headers[USER_AGENT] = 'Travel Time Ruby SDK'
17
+ env.request_headers[USER_AGENT] = "Travel Time Ruby SDK #{TravelTime::VERSION}"
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TravelTime
4
- VERSION = '0.5.4'
4
+ VERSION = '0.5.6'
5
5
  end
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.5.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - TravelTime Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
66
  version: 3.21.9
67
+ - !ruby/object:Gem::Dependency
68
+ name: ruby-limiter
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 2.2.2
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 2.2.2
67
81
  description: TravelTime SDK for Ruby programming language
68
82
  email:
69
83
  - support@traveltime.com