Skip to content

Instantly share code, notes, and snippets.

@come-maiz
Created September 23, 2016 17:58
Show Gist options
  • Save come-maiz/586804b1786f9b5680e0004d7d8c3907 to your computer and use it in GitHub Desktop.
Save come-maiz/586804b1786f9b5680e0004d7d8c3907 to your computer and use it in GitHub Desktop.
Mapbox CLI testing

Smoke tests for the Mapbox CLI snap (based on https://github.com/mapbox/mapbox-cli-py#setup)

First, build and install the snap:

$ sudo apt install git snapcraft
$ git clone https://github.com/elopio/mapbox-cli-py
$ cd mapbox-cli-py
$ git checkout snapcraft
$ snapcraft
$ sudo snap install *.snap --force-dangerous

Print the help:

$ mapbox
$ mapbox --help
Usage: mapbox [OPTIONS] COMMAND [ARGS]...

  This is the command line interface to Mapbox web services.
[...]

Print the version:

$ mapbox --version
0.4.0

The following steps require a Mapbox account and an API token. You can get one for free at https://www.mapbox.com/studio/account/tokens/

Setup the token:

$ export MAPBOX_ACCESS_TOKEN=$TOKEN

Get directions:

$ mapbox directions "[-122.681032, 45.528334]" "[-122.71679, 45.525135]"
{"origin":{"type":"Feature","geometry":{"type":"Point","coordinates":[-122.681041,45.528333]},"properties":{"name":""}},[...]}

Get distance:

$ mapbox distance "[-122.681, 45.528]" "[-122.716, 45.525]"
Error: {"message":"This API currently is in preview. Please contact us at https://mapbox.com/contact/ to get access.","code":"Forbidden"}

Get geocoding:

$ mapbox geocoding '1600 pennsylvania ave nw'
{"type":"FeatureCollection","query":["1600","pennsylvania","ave","nw"],[...]}

Get mapmatching:

$ wget http://people.ubuntu.com/~elopio/testfiles/2251126.geojson
$ mapbox mapmatching 2251126.geojson 
{"code":"Ok","type":"FeatureCollection","features":[...]}

Get staticmap:

$ mapbox staticmap --lon -61.7 --lat 12.1 --zoom 12 mapbox.satelliteout out.png
$ eog out.png

Get surface:

$ mapbox surface mapbox.mapbox-terrain-v1 contour ele "[-122.781, 45.528]" "[-122.716, 45.525]"
Error: {"message":"Feature not enabled. Please read https://www.mapbox.com/blog/introducing-the-surface-api for more information."}

The following step requires a secret token with uploads:write scope.

Upload a geojson:

$ mapbox upload 2251126.geojson $MAPBOX_USERNAME.data
{"id":"[...]","name":"data","complete":false,"error":null,"created":"[...]","modified":"[...]","tileset":"$MAPBOX_USERNAME.data","owner":"$MAPBOX_USERNAME","progress":0}

List datasets:

$ mapbox datasets list
@come-maiz
Copy link
Author

Tested in a clean xenial kvm. Everything works except the datasets command, that return:
Error: {"message":"Not Found"}
That doesn't seem to be a problem in the snap though, I'm getting the same using the package installed in a virtualenv with pip. Maybe I'm using it wrong.

@tnoulas
Copy link

tnoulas commented Jun 7, 2018

Hi, I am simply doing 'mapbox datasets list' and I still get 'Error: {"message":"Not Found"}' ... is this broken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment