aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tom_tom.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb
index 4a6a58df0..a2ebeb1a8 100644
--- a/lib/tom_tom.rb
+++ b/lib/tom_tom.rb
@@ -14,6 +14,19 @@ class TomTom
end
end
+ def calculate_route(way_costs)
+ params = URI.encode_www_form({
+ travelMode: 'bus',
+ routeType: 'shortest'
+ })
+ locations = convert_way_costs_for_calculate_route(way_costs)
+
+ response = @connection.post do |req|
+ req.url "/routing/1/calculateRoute/#{locations}/json?#{params}"
+ req.headers['Content-Type'] = 'application/json'
+ end
+ end
+
def batch(way_costs)
params = URI.encode_www_form({
travelMode: 'bus',
@@ -32,6 +45,16 @@ class TomTom
batchItems: batch_items
}.to_json
end
+
+ response = JSON.parse(response.body)
+
+ calculated_routes = response['batchItems']
+
+ calculated_routes.each do |route|
+ next if route['statusCode'] != 200
+
+ distance = route['response']['routes']
+ end
end
def convert_way_costs_for_batch(way_costs)
@@ -40,4 +63,17 @@ class TomTom
":#{way_cost.arrival.lat},#{way_cost.arrival.lng}"
end
end
+
+ def convert_way_costs_for_calculate_route(way_costs)
+ coordinates = []
+
+ way_costs.map do |way_cost|
+ coordinates << "#{way_cost.departure.lat},#{way_cost.departure.lng}"
+ coordinates << "#{way_cost.arrival.lat},#{way_cost.arrival.lng}"
+ end
+
+ coordinates
+ .uniq
+ .join(':')
+ end
end