Add Mapbox Geocoding v6 lookup#1709
Conversation
The :mapbox lookup uses the Geocoding v5 API. Mapbox has released the
Geocoding v6 API with different endpoints and a new structured response
format. Following the precedent of the Mapquest :open option, this adds
an opt-in version option to the existing lookup:
Geocoder.configure(mapbox: {version: 6})
v5 remains the default so existing users are unaffected. The v6
response format is parsed by a separate result class
(Geocoder::Result::MapboxV6), which keeps the v5 code easy to remove
once Mapbox sunsets the old API.
Closes alexreisner#1708
148828b to
2fd3ec6
Compare
Exposes the v6 response's properties.coordinates.accuracy value (rooftop / parcel / point / interpolated / approximate / intersection), following the precedent of Geocoder::Result::Google#precision which returns the semantically equivalent location_type. Returns nil for administrative features (country, region, etc.) which carry no accuracy value.
|
Thanks for this great PR! The code looks good with one exception. APIs change all the time, and one goal of Geocoder is to save users from having to think about those changes, while allowing them to use the latest/recommended API versions. So I think the default behavior for people using the |
|
@alexreisner Thank you, this makes a lot of sense to me! I agree with the philosophy that To answer your question directly: I do not see a compelling reason to keep v5 supported long-term. In the live comparison, v6 returned identical values for every shared field, and it additionally fills There is one migration detail that I would like your call on, since it is the only thing I can see that might silently break existing apps: Permanent storage. In v5, this is configured through the dataset: Geocoder.configure(mapbox: { dataset: "mapbox.places-permanent" })In v6, the dataset concept is gone and a request param is used instead, which already works today through Geocoder's generic Geocoder.search(address, params: { permanent: true })The concern is that anyone currently relying on How do you think we should handle this? Personally, I lean toward simply documenting it with a CHANGELOG / README migration note. That said, if you would prefer to emit a temporary deprecation instead, I am happy to map a permanent |
Closes #1708
Summary
Adds opt-in support for the Mapbox Geocoding v6 API to the existing
:mapboxlookup:v5 remains the default, so existing users are unaffected. Since the public result interface is identical between the two versions, this switches versions via configuration within the one lookup rather than registering a separate
:mapbox_v6lookup.Design references
The design follows existing patterns in this gem:
:openoption, which switches between the licensed and open endpoint families within one lookup (lib/geocoder/lookups/mapquest.rb#L19, introduced in Changes to the Mapquest Service; includes support for the premium service #315).Geocoder::Result::MapboxV6class, both because the response shapes are genuinely different and to keep the v5 code easy to delete later. When Mapbox eventually sunsets v5, removing it amounts to dropping theelsebranches andresults/mapbox.rb— similar to how the HERE lookup was migrated to API v7 in place (Update HERE lookup to use Geocoder and Search API #1575, released in 1.8.0 with a CHANGELOG note).#precisionaccessor: the v6 result exposesproperties.coordinates.accuracy(rooftop/parcel/interpolated/ ...) as#precision, followingGeocoder::Result::Google#precisionwhich returns the semantically equivalentlocation_type.API differences handled
version: 6)GET /geocoding/v5/{dataset}/{query}.jsonGET /search/geocode/v6/forward?q={query}{lon},{lat}.jsonin pathGET /search/geocode/v6/reverse?longitude=&latitude=mapbox.places-permanent)permanent=truerequest paramplace_nameproperties.full_addressidprefixproperties.contextobjectproperties.short_code(US-NY, needs splitting)context.region.region_code(NY)properties.short_codecontext.country.country_codeChanges
lib/geocoder/lookups/mapbox.rb—version: 6branches for endpoint and params; v5 paths untouched. SameInvalidApiKeyhandling and semicolon truncation (Exception thrown when using mapbox and query contains semicolons #1299) apply to both versionslib/geocoder/results/mapbox_v6.rb— parses the structuredproperties.contextobject; adds a#precisionaccessor for the v6 accuracy valuemapbox_*patterns (test_helper.rbpicks the fixture prefix by configured version)README_API_GUIDE.md— documents theversionoption under the existing Mapbox sectionVerified with live API
Ran the same queries through v5 and v6 with a real access token to confirm the result interfaces line up.
Notes from live verification:
street(v5'sstreetreadsproperties.address, which the live v5 API no longer populates for these queries) and exposesprecision.Not Authorized - Invalid Tokenon v6 too, so the existingGeocoder::InvalidApiKeyhandling works unchanged.Tests