OneBusAway / onebusaway-alexa

An Java-based app to communicate with Amazon Alexa for devices such as the Amazon Echo
Other
52 stars 18 forks source link

Improve region discovery #14

Closed barbeau closed 8 years ago

barbeau commented 8 years ago

From https://github.com/OneBusAway/onebusaway-alexa/pull/8#issuecomment-185287864:

Here's what I'm thinking:

  1. Get location of city (we're already doing this)
  2. Use OBA Regions API to get the closest region:
ObaRegionsResponse response = ObaRegionsRequest.newRequest().call();
ArrayList<ObaRegion> regions = new ArrayList<ObaRegion>(Arrays.asList(response.getRegions()));
ObaRegion r = RegionUtils.getClosestRegion(regions, location);

3.Get and persist the base URL for the closest region:

String baseUrl = r.getObaBaseUrl();

Then just set the client with the persisted base URL when the user asks for arrival times. There needs to be some error handling here, but this would allow for an open set of cities, so we don't need to modify OBA Alexa when more cities are added to the Regions API.

When I mention "error handling" above, I'm primarily thinking of the case where the user specifies a city name but the closest OBA region is hundreds of miles from their location. We can offer to give them data for that region, but it's probably not relevant to them.

barbeau commented 8 years ago

As far as persistence, here's what I originally envisioned to be in the data model:

private String userId;  // We currently have this
private String city;  // We currently have this
private int regionId;
private String obaBaseUrl;
private String currentStopId;  // We currently have this
private String currentStopCode;  // See https://github.com/OneBusAway/onebusaway-alexa/issues/13

So I think for this issue we just need to add the regionId and obaBaseUrl. Ideally we should refresh the obaBaseUrl for the region from the Regions API occasionally, which is where the regionId comes in (regionId is guaranteed to always remain the same for each region).

barbeau commented 8 years ago

I'm going to take a shot at implementing this.