Skip to content

Commit

Permalink
Merge 952f12d into 9e6da71
Browse files Browse the repository at this point in the history
  • Loading branch information
willwhite committed Jul 30, 2015
2 parents 9e6da71 + 952f12d commit eee374d
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var xtend = require('xtend/mutable');
var MapboxGeocoder = require('./services/geocoder');
var MapboxSurface = require('./services/surface');
var MapboxDirections = require('./services/directions');
var MapboxUploads = require('./services/uploads');
var MapboxMatching = require('./services/matching');
var MapboxDatasets = require('./services/datasets');

Expand All @@ -29,6 +30,7 @@ xtend(MapboxClient.prototype,
MapboxSurface.prototype,
MapboxDirections.prototype,
MapboxMatching.prototype,
MapboxDatasets.prototype);
MapboxDatasets.prototype,
MapboxUploads.prototype);

module.exports = MapboxClient;
3 changes: 3 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module.exports.API_GEOCODER_FORWARD = compile('${endpoint}/v4/geocode/${dataset}
module.exports.API_GEOCODER_REVERSE = compile('${endpoint}/v4/geocode/${dataset}/${location.longitude},${location.latitude}.json?${query}');
module.exports.API_DIRECTIONS = compile('${endpoint}/v4/directions/${profile}/${encodedWaypoints}.json?${query}');
module.exports.API_SURFACE = compile('${endpoint}/v4/surface/${mapid}.json?${query}');
module.exports.API_UPLOADS = compile('${endpoint}/uploads/v1/${owner}?${query}');
module.exports.API_UPLOAD = compile('${endpoint}/uploads/v1/${owner}/${upload}?${query}');
module.exports.API_UPLOAD_CREDENTIALS = compile('${endpoint}/uploads/v1/${owner}/credentials?${query}');
module.exports.API_MATCHING = compile('${endpoint}/matching/v4/${profile}.json?${query}');
module.exports.API_DATASET_DATASETS = compile('${endpoint}/datasets/v1/${owner}?${query}');
module.exports.API_DATASET_DATASET = compile('${endpoint}/datasets/v1/${owner}/${dataset}?${query}');
Expand Down
143 changes: 143 additions & 0 deletions lib/services/uploads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
'use strict';

var invariant = require('invariant'),
request = require('superagent'),
makeService = require('../make_service'),
constants = require('../constants'),
makeURL = require('../make_url');

var Uploads = module.exports = makeService('MapboxUploads');

/**
* To retrieve a listing of uploads for a particular account.
* This request requires an access token with the uploads:list scope.
*
* @param {Function} callback called with (err, uploads)
* @returns {undefined} nothing, calls callback
* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.listUploads(function(err, uploads) {
* console.log(uploads);
* // [
* // {
* // "complete": true,
* // "tileset": "example.mbtiles",
* // "error": null,
* // "id": "abc123",
* // "modified": "2014-11-21T19:41:10.000Z",
* // "created": "2014-11-21T19:41:10.000Z",
* // "owner": "example",
* // "progress": 1
* // },
* // {
* // "complete": false,
* // "tileset": "example.foo",
* // "error": null,
* // "id": "xyz789",
* // "modified": "2014-11-21T19:41:10.000Z",
* // "created": "2014-11-21T19:41:10.000Z",
* // "owner": "example",
* // "progress": 0
* // }
* // ]
* });
*/
Uploads.prototype.listUploads = function(owner, callback) {
// defaults to the owner of the provided token if omitted
if (callback === undefined && typeof owner === 'function') {
callback = owner;
owner = this.user;
}

invariant(typeof callback === 'function', 'callback must be a function');
invariant(typeof owner === 'string', 'owner must be a string');

var url = makeURL(this, constants.API_UPLOADS, { owner: owner });

request(url, function(err, res) {
callback(err, res.body);
});
};

Uploads.prototype.createUploadCredentials = function(owner, callback) {
// defaults to the owner of the provided token if omitted
if (callback === undefined && typeof owner === 'function') {
callback = owner;
owner = this.user;
}

invariant(typeof callback === 'function', 'callback must be a function');
invariant(typeof owner === 'string', 'owner must be a string');

var url = makeURL(this, constants.API_UPLOAD_CREDENTIALS, { owner: owner });

request
.get(url)
.end(function(err, res) {
callback(err, res.body);
});
};

Uploads.prototype.createUpload = function(options, owner, callback) {
// defaults to the owner of the provided token if omitted
if (callback === undefined && typeof owner === 'function') {
callback = owner;
owner = this.user;
}

invariant(typeof options === 'object', 'options must be an object');
invariant(typeof owner === 'string', 'owner must be a string');
invariant(typeof callback === 'function', 'callback must be a function');

var url = makeURL(this, constants.API_UPLOADS, { owner: owner });

request
.post(url)
.send(options)
.end(function(err, res) {
callback(err, res.body);
});
};

Uploads.prototype.readUpload = function(upload, owner, callback) {
// defaults to the owner of the provided token if omitted
if (callback === undefined && typeof owner === 'function') {
callback = owner;
owner = this.user;
}

invariant(typeof upload === 'string', 'upload must be a string');
invariant(typeof callback === 'function', 'callback must be a function');

var url = makeURL(this, constants.API_UPLOAD, {
owner: owner,
upload: upload
});

request(url, function(err, res) {
callback(err, res.body);
});
};

Uploads.prototype.deleteUpload = function(upload, owner, callback) {
// defaults to the owner of the provided token if omitted
if (callback === undefined && typeof owner === 'function') {
callback = owner;
owner = this.user;
}

invariant(typeof upload === 'string', 'upload must be a string');
invariant(typeof owner === 'string', 'owner must be a string');
invariant(typeof callback === 'function', 'callback must be a function');

var url = makeURL(this, constants.API_UPLOAD, {
owner: owner,
upload: upload
});

request
.del(url)
.end(function(err) {
callback(err);
});
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
},
"homepage": "https://github.com/mapbox/mapbox-sdk-js",
"devDependencies": {
"aws-sdk": "^2.1.41",
"browserify": "^11.0.0",
"documentation": "^2.1.0-alpha2",
"eslint": "^0.24.1",
"geojson-random": "^0.2.2",
"geojsonhint": "^1.1.0",
"hat": "0.0.3",
"polyline": "^0.1.0",
"tap": "^1.3.1",
"uglifyjs": "^2.4.10"
Expand Down
Binary file added test/fixtures/valid-onlytiles.mbtiles
Binary file not shown.

0 comments on commit eee374d

Please sign in to comment.