aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-03-27 11:18:17 +0200
committerTeddy Wing2018-03-27 16:46:18 +0200
commitf257a8b3a7ae4c59c6907b41f6e8d7dc74259917 (patch)
tree0178b9cd432c1c54b48fd25e9360c4d710972bf1
parentf03f942ecb9b802664dee0cc0f33f96a566c67e9 (diff)
downloadchouette-core-f257a8b3a7ae4c59c6907b41f6e8d7dc74259917.tar.bz2
RouteWayCostCalculator: Use `TomTom.matrix` instead of batch
Calculate routes using the TomTom matrix API. Update the spec's HTTP request stub accordingly (note that the stub is still fake). Refs #6222
-rw-r--r--app/services/route_way_cost_calculator.rb2
-rw-r--r--spec/services/route_way_cost_calculator_spec.rb10
2 files changed, 7 insertions, 5 deletions
diff --git a/app/services/route_way_cost_calculator.rb b/app/services/route_way_cost_calculator.rb
index 2e30c94fc..d41a2e59a 100644
--- a/app/services/route_way_cost_calculator.rb
+++ b/app/services/route_way_cost_calculator.rb
@@ -5,7 +5,7 @@ class RouteWayCostCalculator
def calculate!
way_costs = StopAreasToWayCostsConverter.new(@route.stop_areas).convert
- way_costs = TomTom.batch(way_costs)
+ way_costs = TomTom.matrix(way_costs)
way_costs = WayCostCollectionJSONSerializer.dump(way_costs)
@route.update(costs: way_costs)
end
diff --git a/spec/services/route_way_cost_calculator_spec.rb b/spec/services/route_way_cost_calculator_spec.rb
index d5358fcf6..79b81e34d 100644
--- a/spec/services/route_way_cost_calculator_spec.rb
+++ b/spec/services/route_way_cost_calculator_spec.rb
@@ -7,18 +7,20 @@ RSpec.describe RouteWayCostCalculator do
# things in the request or response. This is just to fake the request so
# we don't actually call their API in tests. The test doesn't test
# anything given in the response.
- stub_request(:post, "https://api.tomtom.com/routing/1/batch/json?key")
+ stub_request(
+ :post,
+ "https://api.tomtom.com/routing/1/matrix/json?key&routeType=shortest&travelMode=bus"
+ )
.with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json',
'User-Agent'=>'Faraday v0.9.2'
- }
- )
+ })
.to_return(
status: 200,
- body: "{\"formatVersion\":\"0.0.1\",\"batchItems\":[{\"statusCode\":200,\"response\":{\"routes\":[{\"summary\":{\"lengthInMeters\":117947,\"travelTimeInSeconds\":7969,\"trafficDelayInSeconds\":0,\"departureTime\":\"2018-03-12T12:32:26+01:00\",\"arrivalTime\":\"2018-03-12T14:45:14+01:00\"}}]}}]}",
+ body: "{\"formatVersion\":\"0.0.1\",\"matrix\":[[{\"statusCode\":200,\"response\":{\"routeSummary\":{\"lengthInMeters\":0,\"travelTimeInSeconds\":0,\"trafficDelayInSeconds\":0,\"departureTime\":\"2018-03-23T11:20:17+01:00\",\"arrivalTime\":\"2018-03-23T11:20:17+01:00\"}}}]]}",
headers: {}
)