From 8a9de08cfffd8f2d6e73a90472cc070a06fdc5b3 Mon Sep 17 00:00:00 2001 From: mockusTraveltTime Date: Tue, 9 Apr 2024 16:51:06 +0300 Subject: [PATCH 1/5] add distance map function --- lib/travel_time/client.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/travel_time/client.rb b/lib/travel_time/client.rb index d5ffdae..4f096d1 100644 --- a/lib/travel_time/client.rb +++ b/lib/travel_time/client.rb @@ -108,6 +108,16 @@ def time_map(departure_searches: nil, arrival_searches: nil, unions: nil, inters perform_request { connection.post('time-map', payload, { 'Accept' => format }) } end + def distance_map(departure_searches: nil, arrival_searches: nil, unions: nil, intersections: nil, format: nil) + payload = { + departure_searches: departure_searches, + arrival_searches: arrival_searches, + unions: unions, + intersections: intersections + }.compact + perform_request { connection.post('distance-map', payload, { 'Accept' => format }) } + end + def time_map_fast(arrival_searches:, format: nil) payload = { arrival_searches: arrival_searches From fbd70b8ceddd2d982532429c16557819f2b3b0eb Mon Sep 17 00:00:00 2001 From: mockusTraveltTime Date: Tue, 9 Apr 2024 16:54:25 +0300 Subject: [PATCH 2/5] add readme update --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index 5aa4ff9..b7e3693 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,64 @@ response = client.time_map( puts response.body ``` +### [Distance Map](https://docs.traveltime.com/api/reference/distance-map) +Given origin coordinates, find shapes of zones reachable within corresponding travel distance. +Find unions/intersections between different searches. + +Body attributes: +* departure_searches: Searches based on departure times. Leave departure location at no earlier than given time. You can define a maximum of 10 searches. +* 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. +* unions: Define unions of shapes that are results of previously defined searches. +* intersections: Define intersections of shapes that are results of previously defined searches. + +```ruby +require 'time' + +departure_search = { + id: "driving from Trafalgar Square", + coords: { + lat: 51.506756, + lng: -0.128050 + }, + transportation: { type: "driving" }, + departure_time: Time.now.iso8601, + travel_distance: 1800, +} + +arrival_search = { + id: "cycling to Trafalgar Square", + coords: { + lat: 51.506756, + lng: -0.128050 + }, + transportation: { type: "cycling" }, + arrival_time: Time.now.iso8601, + travel_distance: 1800, + range: { enabled: true, width: 3600 } +} + +union = { + id: 'union of driving and cycling', + search_ids: ['driving from Trafalgar Square', 'cycling to Trafalgar Square'] +} + +intersection = { + id: 'intersection of driving and cycling', + search_ids: ['driving from Trafalgar Square', 'cycling to Trafalgar Square'] +} + +client.hello_world + +response = client.distance_map( + departure_searches: [departure_search], + arrival_searches: [arrival_search], + unions: [union], + intersections: [intersection] +) + +puts response.body +``` + ### [Isochrones (Time Map) Fast](https://docs.traveltime.com/api/reference/isochrones-fast) A very fast version of Isochrone API. However, the request parameters are much more limited. From 68920e86308171bfe8e80d94f6007328dccc113b Mon Sep 17 00:00:00 2001 From: mockusTraveltTime Date: Tue, 9 Apr 2024 16:55:10 +0300 Subject: [PATCH 3/5] fix links --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b7e3693..084c89c 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ You may specify an optional rate limit when initializing your client. The `rate_ client = TravelTime::Client.new(rate_limit = 60) ``` -### [Isochrones (Time Map)](https://traveltime.com/docs/api/reference/isochrones) +### [Isochrones (Time Map)](https://docs.traveltime.com/api/reference/isochrones) Given origin coordinates, find shapes of zones reachable within corresponding travel time. Find unions/intersections between different searches. @@ -219,7 +219,7 @@ response = client.time_map_fast( puts response.body ``` -### [Distance Matrix (Time Filter)](https://traveltime.com/docs/api/reference/distance-matrix) +### [Distance Matrix (Time Filter)](https://docs.traveltime.com/api/reference/distance-matrix) Given origin and destination points filter out points that cannot be reached within specified time limit. Find out travel times, distances and costs between an origin and up to 2,000 destination points. @@ -285,7 +285,7 @@ response = client.time_filter( puts response.body ``` -### [Time Filter (Fast)](https://traveltime.com/docs/api/reference/time-filter-fast) +### [Time Filter (Fast)](https://docs.traveltime.com/api/reference/time-filter-fast) A very fast version of `time_filter()`. However, the request parameters are much more limited. @@ -384,7 +384,7 @@ puts(response.body) 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. -### [Routes](https://traveltime.com/docs/api/reference/routes) +### [Routes](https://docs.traveltime.com/api/reference/routes) Returns routing information between source and destinations. Body attributes: @@ -455,7 +455,7 @@ response = client.routes( puts response.body ``` -### [Geocoding (Search)](https://traveltime.com/docs/api/reference/geocoding-search) +### [Geocoding (Search)](https://docs.traveltime.com/api/reference/geocoding-search) Match a query string to geographic coordinates. ```ruby @@ -463,7 +463,7 @@ response = client.geocoding(query: 'London', within_country: 'GB') puts response.body ``` -### [Reverse Geocoding](https://traveltime.com/docs/api/reference/geocoding-reverse) +### [Reverse Geocoding](https://docs.traveltime.com/api/reference/geocoding-reverse) Attempt to match a latitude, longitude pair to an address. ```ruby @@ -471,7 +471,7 @@ response = client.reverse_geocoding(lat: 51.506756, lng: -0.128050) puts response.body ``` -### [Time Filter (Postcodes)](https://traveltime.com/docs/api/reference/postcode-search) +### [Time Filter (Postcodes)](https://docs.traveltime.com/api/reference/postcode-search) Find reachable postcodes from origin (or to destination) and get statistics about such postcodes. Currently only supports United Kingdom. @@ -504,7 +504,7 @@ response = client.time_filter_postcodes( puts response.body ``` -### [Time Filter (Postcode Districts)](https://traveltime.com/docs/api/reference/postcode-district-filter) +### [Time Filter (Postcode Districts)](https://docs.traveltime.com/api/reference/postcode-district-filter) Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts. Currently only supports United Kingdom. @@ -539,7 +539,7 @@ response = client.time_filter_postcode_districts( puts response.body ``` -### [Time Filter (Postcode Sectors)](https://traveltime.com/docs/api/reference/postcode-sector-filter) +### [Time Filter (Postcode Sectors)](https://docs.traveltime.com/api/reference/postcode-sector-filter) Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors. Currently only supports United Kingdom. @@ -574,7 +574,7 @@ response = client.time_filter_postcode_sectors( puts response.body ``` -### [Map Info](https://traveltime.com/docs/api/reference/map-info) +### [Map Info](https://docs.traveltime.com/api/reference/map-info) Get information about currently supported countries. ```ruby @@ -582,7 +582,7 @@ response = client.map_info puts response.body ``` -### [Supported Locations](https://traveltime.com/docs/api/reference/supported-locations) +### [Supported Locations](https://docs.traveltime.com/api/reference/supported-locations) Find out what points are supported by the api. ```ruby From bfcaba31f0b751e6b64d7b9f305f90b68d626be4 Mon Sep 17 00:00:00 2001 From: mockusTraveltTime Date: Tue, 9 Apr 2024 16:57:36 +0300 Subject: [PATCH 4/5] add tests for distance map --- spec/travel_time/client_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/travel_time/client_spec.rb b/spec/travel_time/client_spec.rb index 5c722b5..2b21beb 100644 --- a/spec/travel_time/client_spec.rb +++ b/spec/travel_time/client_spec.rb @@ -111,6 +111,15 @@ it_behaves_like 'an endpoint method' end + describe '#distance_map' do + subject(:response) { client.distance_map } + + let(:url) { "#{described_class::API_BASE_URL}distance-map" } + let(:stub) { stub_request(:post, url) } + + it_behaves_like 'an endpoint method' + end + describe '#time_map_fast' do subject(:response) { client.time_map_fast(arrival_searches: []) } From 94cccd26c71e85cc82d017fca6dc2eda11013d5f Mon Sep 17 00:00:00 2001 From: mockusTraveltTime Date: Tue, 9 Apr 2024 17:10:45 +0300 Subject: [PATCH 5/5] remove leftover code --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 084c89c..ebfd1cf 100644 --- a/README.md +++ b/README.md @@ -181,8 +181,6 @@ intersection = { search_ids: ['driving from Trafalgar Square', 'cycling to Trafalgar Square'] } -client.hello_world - response = client.distance_map( departure_searches: [departure_search], arrival_searches: [arrival_search],