aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tom_tom.rb
AgeCommit message (Collapse)Author
2018-05-13Test api_key format in TomTom.enabled?. Refs #6993Alban Peignier
2018-05-13Define a dummy TomTom api_key in specAlban Peignier
2018-03-27Add `TomTom::Matrix`Teddy Wing
A new component to the `TomTom` module that asks TomTom's Matrix API endpoint (https://developer.tomtom.com/online-routing/online-routing-documentation/matrix-routing) to compute `WayCost`s. The matrix API will give us all costs between each pair of coordinates. This will enable us to provide costs for any combination of points in a journey pattern. Given a list of `WayCost`s, it will send all points from those costs to the matrix API and return a list of all non-zero `WayCost`s between all pairs of coordinates. `points_from_way_costs()` extracts unique coordinates from the `WayCost`s. `points_as_params()` builds a list of points in the format expected by the matrix API. The response from the matrix API is formatted as a two-dimensional array consisting of rows and columns that pair each "origin" point with each "destination" point. We loop through this matrix and construct new `WayCost` objects for each pair of coordinates. At the moment, I haven't figured out how I want to save `WayCost` IDs when creating the new pairs. Leaving that for later. Refs #6222
2018-03-15Route: Don't run `#calculate_costs!` on callback if TomTom disabledTeddy Wing
We say `TomTom` is disabled when no API key is present. If this is the case, the `after_save` callback that uses it shouldn't be executed. I had to change my `API_KEY` constant to an instance variable to be able to change it for testing. Refs #6095
2018-03-14TomTom: Provide `TomTom.batch(...)` methodTeddy Wing
This change enables us to call `TomTom.batch(...)` instead of `TomTom.new.batch(...)` a couple commits ago. This is nice because the initialisation was kind of unnecessary for users of the class. Refs #6095
2018-03-14Move `lib/tom_tom.rb` to `lib/tom_tom/batch.rb`Teddy Wing
Separate the functionality a little better by moving the `/batch` endpoint code into a new class. The goal here is also to lay the foundation for being able to call `TomTom.batch()` instead of `TomTom.new.batch()`. Refs #6095
2018-03-14TomTom#batch: Populate WayCosts with distance & time from APITeddy Wing
Look through the API response from `/batch` and extract the distance & time values given to us by TomTom. These are inserted in the `WayCost`s given to use in the argument to `#batch`. At the end, we get a list of `WayCost`s that are completely filled with distance & time values. We need to split up this code a bit to make it more testable, but already this seems to function correctly. Refs #6095
2018-03-14secrets.yml: Add `tomtom_api_key`Teddy Wing
Make the TomTom API key accessible to the application. It gets set in Docker via an environment variable. Still need to work out how we're setting it in development. For now I'm just saving it in `secrets.yml` without committing it. Refs #6095
2018-03-14Revert "TomTom: Add method for `calculateRoute` endpoint"Teddy Wing
This reverts commit f28a4b2c5b348bc12b455aa0cd76a9513103aea7. As stated in that commit, I'm going to use the `/batch` endpoint instead of `/calculateRoute` because I know that's already working.
2018-03-14TomTom: Add method for `calculateRoute` endpointTeddy Wing
A new method to provide access to the `/calculateRoute` endpoint, which calculates costs for a single route through a bunch of waypoints. This doesn't work currently because the API requires that I send `supportingPoints` in the body of the request. Since I'm not too clear on what those are, I'm going to cut off development of this method here and just use `#batch` instead for my purposes. My idea was to use this endpoint instead of `/batch` to allow us to calculate a single route instead of having the API do `/calculateRoute` for each of our point pairs. This seemed like it would be more efficient, and give us our distance and time costs between each waypoint all in one go, but since I'm not clear on how to use this API and whether it will give us the correct data, I'm going to stick with `/batch`. I'll probably be reverting this code. Just committing it now in case it becomes useful in the future. Refs #6095
2018-03-14TomTom#batch: Remove unwanted paramsTeddy Wing
I had copy-pasted these from the example in the docs (https://developer.tomtom.com/online-routing/online-routing-documentation/batch-routing), but I don't think we want some of these. For `maxAlternatives`, it's already 0 by default according to their docs, and the others don't really make sense for us because we want a general routing instead of one based on traffic or time of day. Refs #6095
2018-03-14TomTom: Use travelMode='bus'Teddy Wing
For now, hard-code 'bus' as the travel mode. This feature is currently only going to be used for Ouibus, so we want to be able to request in 'bus' mode, but for now don't have time to think about how to make it more extensible to other travel modes and operators. Refs #6095
2018-03-14TomTom: Remove old commented codeTeddy Wing
These served during development but are no longer needed. Refs #6095
2018-03-14Add `TomTom` class to communicate with their APITeddy Wing
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