From b27dd5fe2f061e2ef94d250fc5a06c1d8e84179a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 9 Mar 2018 15:55:49 +0100 Subject: Add `TomTom` class to communicate with their API Provides an interface to communicate with the TomTom API. Currently includes a method `#batch` to make a batch routing request (https://developer.tomtom.com/online-routing/online-routing-documentation/batch-routing). Left a bunch of development-related code in just to preserve my in-progress stages. Originally I was told to use the matrix routing API, but that turned out to not match what we wanted. Namely, matrix routing would produce a table with every point routed with every other point. We instead want routes of each segment in a line, in order (or, just the diagonal of the matrix). Using the batch API allows us to get the routes we need without doing unnecessary work. Update the `WayCost` class to provide `departure` and `arrival` methods as readers, and make `id` an optional parameter for now. (We still need to figure out how we're dealing with ID.) Refs #6095 --- spec/lib/tom_tom_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/lib/tom_tom_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/tom_tom_spec.rb b/spec/lib/tom_tom_spec.rb new file mode 100644 index 000000000..57f22d26a --- /dev/null +++ b/spec/lib/tom_tom_spec.rb @@ -0,0 +1,25 @@ +RSpec.describe TomTom do + let(:tomtom) { TomTom.new } + + describe "#convert_way_costs_for_batch" do + it "turns WayCost points into a collection of colon-separated strings" do + way_costs = [ + WayCost.new( + departure: Geokit::LatLng.new(2, 48), + arrival: Geokit::LatLng.new(3, 46) + ), + WayCost.new( + departure: Geokit::LatLng.new(-71, 42), + arrival: Geokit::LatLng.new(-71.5, 42.9) + ) + ] + + expect( + tomtom.convert_way_costs_for_batch(way_costs) + ).to eq([ + '2,48:3,46', + '-71,42:-71.5,42.9' + ]) + end + end +end -- cgit v1.2.3