Repository navigation
Add mapbox places, full detail for one or more Search Box result ids #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattpodwysocki
wants to merge
3
commits into
main
Choose a base branch
from
feat/places-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| openapi: "3.0.0" | ||
| # `parse_spec` turns `info.description` below into this service's clap | ||
| # `long_about`, so it also reaches `mapbox places --help`, `--schema` and | ||
| # `generate-skills` output. Keep it to API prose only — the provenance | ||
| # below is for whoever edits this file, not for a CLI user: | ||
| # | ||
| # Hand-authored down to the parameters documented at | ||
| # docs.mapbox.com/api/search/places. See `custom-openapi/README.md` for | ||
| # how a file like this is wired in. | ||
| # | ||
| # One command, not two: the API has a single-id GET and a batch POST, and | ||
| # an earlier version of this file exposed both as `places get`/`places | ||
| # batch`. Reviewed as the wrong shape for any API with that pair — a | ||
| # caller should not have to choose between "one id" and "a JSON array of | ||
| # ids" written by hand. `batch` is the one that survives, renamed to the | ||
| # bare `places` command via `FLATTENED_SERVICES`, taking one or more ids | ||
| # as positional arguments (`VARIADIC_BODY_ARRAY` in `src/spec.rs`) and | ||
| # always using the batch endpoint — even for a single id — so there is one | ||
| # response shape and one code path. The GET operation this used to expose | ||
| # as `places get` is gone from here entirely, not just hidden: nothing | ||
| # reaches it. | ||
| info: | ||
| title: "Mapbox Places API" | ||
| description: >- | ||
| Full detail for one or more places — hours, phone, website, photos, | ||
| address, coordinates, activity data — by the `mapbox_id`s a Search Box | ||
| API result already returned. This API has no search or suggest of its | ||
| own; it only resolves ids something else found. Public Preview, with | ||
| a 1000-records-per-account monthly quota. | ||
| version: "0.0.0" | ||
| servers: | ||
| - url: https://api.mapbox.com | ||
| description: Places API | ||
| paths: | ||
| /places/v1/details/retrieve: | ||
| post: | ||
| operationId: batch | ||
| summary: Full detail for one or more places. | ||
| description: >- | ||
| Each `mapbox_id` comes from a Search Box API result (`search | ||
| forward`/`reverse`/`category`) — this API does not look places up | ||
| by name or location itself. Always sends a batch request, one id | ||
| or many, so a single id reads the same way, no `get`/`batch` | ||
| choice to make. Up to 100 ids in one call. | ||
| parameters: | ||
| - name: "access_token" | ||
| in: query | ||
| required: true | ||
| description: "Mapbox API Access Token" | ||
| schema: | ||
| type: string | ||
| minLength: 1 | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: ["ids"] | ||
| properties: | ||
| ids: | ||
| type: array | ||
| description: >- | ||
| One or more Mapbox IDs, from a Search Box API result, | ||
| up to 100. | ||
| items: | ||
| type: string | ||
| minLength: 1 | ||
| minItems: 1 | ||
| maxItems: 100 | ||
| responses: | ||
| "200": | ||
| description: >- | ||
| Every id resolved: `{"results": [<place record>, ...]}`, one | ||
| entry per id — `name`, `full_address`, `primary_category`/ | ||
| `categories`, `coordinates` (with `routable_points`), | ||
| structured `address`, `score` (`closed`/`reality`/ | ||
| `popularity`, each 0-1), and where available `brand`, | ||
| `opening_hours`, `phone`, `photos`, `website`, `building`, and | ||
| `telemetry` (hourly activity by day of week). | ||
| "206": | ||
| description: >- | ||
| Partial Content — some ids didn't resolve. Same body as 200, | ||
| plus `missing` (ids with no such place) and/or `unprocessed` | ||
| (ids that couldn't be processed) alongside `results`. Treated | ||
| as success, the same as 200 — a caller still gets every id | ||
| that did resolve, and `missing`/`unprocessed` say which ones | ||
| didn't rather than failing the whole request over them. | ||
| "400": | ||
| description: >- | ||
| Bad Request — `ids` isn't a non-empty array of at most 100 | ||
| entries. The 100 limit is also enforced client-side, before | ||
| the request goes out. | ||
| "401": | ||
| description: Unauthorized | ||
| "429": | ||
| description: >- | ||
| Too Many Requests — the per-second rate limit (charged by id | ||
| count) or the Public Preview's monthly quota (1000 | ||
| records/account) was exceeded. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exit 0 when some ids are missing makes sense: the caller still gets the ones that resolved. But when no id resolves,
mapbox places <id>exits 0 with"results": []and prints nothing to stderr. Before,places getfailed with 404. Please exit non-zero in this case. Exit codes are part of the contract, so this is easier to decide before release.Optional: also print the
missing/unprocessedids to stderr.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: when no id resolves at all, the CLI now exits non-zero instead of reporting success with an empty results. The ids that didn't resolve print to stderr too (took your optional suggestion). Tested against production with a well-formed but nonexistent id:
Partial success (some ids resolve, some don't) still exits 0, unchanged.