Comparing version 0.10.0 to 0.11.0
50
API.md
@@ -1,23 +0,1 @@ | ||
## `MapboxClient` | ||
The JavaScript API to Mapbox services | ||
### Parameters | ||
* `accessToken` **`string`** a private or public access token | ||
* `options` **`Object`** additional options provided for configuration | ||
* `options.endpoint` **`[string]`** location of the Mapbox API pointed-to. This can be customized to point to a Mapbox Atlas Server instance, or a different service, a mock, or a staging endpoint. Usually you don't need to customize this. (optional, default `https://api.mapbox.com`) | ||
* `options.account` **`[string]`** account id to use for api requests. If not is specified, the account defaults to the owner of the provided accessToken. | ||
### Examples | ||
```js | ||
var client = new MapboxClient('ACCESSTOKEN'); | ||
``` | ||
| type | description | | ||
| ---- | ----------- | | ||
| `Error` | if accessToken is not provided | | ||
## `bulkFeatureUpdate` | ||
@@ -672,2 +650,6 @@ | ||
* `dataset` **`string`** the id for an existing dataset | ||
* `options` **`[object]`** an object for passing pagination arguments | ||
* `options.reverse` **`[boolean]`** Set to `true` to reverse the default sort order of the listing. | ||
* `options.limit` **`[number]`** The maximum number of objects to return. This value must be between 1 and 100. The API will attempt to return the requested number of objects, but receiving fewer objects does not necessarily signal the end of the collection. Receiving an empty page of results is the only way to determine when you are at the end of a collection. | ||
* `options.start` **`[string]`** The object id that acts as the cursor for pagination and defines your location in the collection. This argument is exclusive so the object associated with the id provided to the start argument will not be included in the response. | ||
* `callback` **`Function`** called with (err, collection) | ||
@@ -681,3 +663,3 @@ | ||
var client = new MapboxClient('ACCESSTOKEN'); | ||
client.listFeatures('dataset-id', function(err, collection) { | ||
client.listFeatures('dataset-id', options, function(err, collection) { | ||
console.log(collection); | ||
@@ -750,2 +732,24 @@ { | ||
## `MapboxClient` | ||
The JavaScript API to Mapbox services | ||
### Parameters | ||
* `accessToken` **`string`** a private or public access token | ||
* `options` **`Object`** additional options provided for configuration | ||
* `options.endpoint` **`[string]`** location of the Mapbox API pointed-to. This can be customized to point to a Mapbox Atlas Server instance, or a different service, a mock, or a staging endpoint. Usually you don't need to customize this. (optional, default `https://api.mapbox.com`) | ||
* `options.account` **`[string]`** account id to use for api requests. If not is specified, the account defaults to the owner of the provided accessToken. | ||
### Examples | ||
```js | ||
var client = new MapboxClient('ACCESSTOKEN'); | ||
``` | ||
| type | description | | ||
| ---- | ----------- | | ||
| `Error` | if accessToken is not provided | | ||
## `matching` | ||
@@ -752,0 +756,0 @@ |
@@ -0,1 +1,9 @@ | ||
## 0.11.0 | ||
- Allow pagination options if passed in listFeatures [#61](https://github.com/mapbox/mapbox-sdk-js/pull/61) | ||
## 0.10.0 | ||
- Support query params for Directions requests [#58](https://github.com/mapbox/mapbox-sdk-js/pull/58) | ||
## 0.9.0 | ||
@@ -2,0 +10,0 @@ |
@@ -16,3 +16,3 @@ // We keep all of the constants that declare endpoints in one | ||
module.exports.API_DATASET_DATASET = '/datasets/v1/{owner}/{dataset}'; | ||
module.exports.API_DATASET_FEATURES = '/datasets/v1/{owner}/{dataset}/features'; | ||
module.exports.API_DATASET_FEATURES = '/datasets/v1/{owner}/{dataset}/features{?reverse,limit,start}'; | ||
module.exports.API_DATASET_FEATURE = '/datasets/v1/{owner}/{dataset}/features/{id}'; | ||
@@ -19,0 +19,0 @@ module.exports.API_TILESTATS_STATISTICS = '/tilestats/v1/{owner}/{tileset}'; |
@@ -212,2 +212,6 @@ 'use strict'; | ||
* @param {string} dataset the id for an existing dataset | ||
* @param {object} [options] an object for passing pagination arguments | ||
* @param {boolean} [options.reverse] Set to `true` to reverse the default sort order of the listing. | ||
* @param {number} [options.limit] The maximum number of objects to return. This value must be between 1 and 100. The API will attempt to return the requested number of objects, but receiving fewer objects does not necessarily signal the end of the collection. Receiving an empty page of results is the only way to determine when you are at the end of a collection. | ||
* @param {string} [options.start] The object id that acts as the cursor for pagination and defines your location in the collection. This argument is exclusive so the object associated with the id provided to the start argument will not be included in the response. | ||
* @param {Function} callback called with (err, collection) | ||
@@ -218,3 +222,3 @@ * @returns {undefined} nothing, calls callback | ||
* var client = new MapboxClient('ACCESSTOKEN'); | ||
* client.listFeatures('dataset-id', function(err, collection) { | ||
* client.listFeatures('dataset-id', options, function(err, collection) { | ||
* console.log(collection); | ||
@@ -240,12 +244,36 @@ * { | ||
*/ | ||
Datasets.prototype.listFeatures = function(dataset, callback) { | ||
Datasets.prototype.listFeatures = function(dataset, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
assert(typeof dataset === 'string', 'dataset must be a string'); | ||
assert(typeof options === 'object', 'options must be a object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
var params = { | ||
owner: this.owner, | ||
dataset: dataset | ||
}; | ||
if (options.reverse) { | ||
assert(typeof options.reverse === 'boolean', 'reverse option must be a boolean'); | ||
params.reverse = options.reverse; | ||
} | ||
if (options.limit) { | ||
assert(typeof options.limit === 'number', 'limit option must be a number'); | ||
params.limit = options.limit; | ||
} | ||
if (options.start) { | ||
assert(typeof options.start === 'string', 'start option must be a string'); | ||
params.start = options.start; | ||
} | ||
this.client({ | ||
path: constants.API_DATASET_FEATURES, | ||
params: { | ||
owner: this.owner, | ||
dataset: dataset | ||
}, | ||
params: params, | ||
callback: callback | ||
@@ -252,0 +280,0 @@ }); |
{ | ||
"name": "mapbox", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "interface to mapbox services", | ||
@@ -12,3 +12,3 @@ "main": "lib/mapbox.js", | ||
"browser-test-build": "echo '<script>' > test_bundle.html && browserify -t envify -t brfs test/directions.js >> test_bundle.html && echo '</script>' >> test_bundle.html", | ||
"docs": "documentation . --format=md > API.md", | ||
"docs": "documentation -f md > API.md", | ||
"build": "npm run build-dist && npm run build-min", | ||
@@ -44,3 +44,3 @@ "build-dist": "browserify -s MapboxClient lib/mapbox.js > dist/mapbox-sdk.js", | ||
"browserify": "^11.0.0", | ||
"documentation": "^2.1.0-alpha2", | ||
"documentation": "^3.0.0", | ||
"envify": "^3.4.0", | ||
@@ -47,0 +47,0 @@ "eslint": "^0.24.1", |
@@ -7,8 +7,13 @@ /* eslint no-shadow: 0 */ | ||
var geojsonhint = require('geojsonhint').hint; | ||
var geojsonRandom = require('geojson-random'); | ||
var hat = require('hat'); | ||
function randomFeature() { | ||
return require('geojson-random').polygon(1).features[0]; | ||
return geojsonRandom.polygon(1).features[0]; | ||
} | ||
function randomFeatures(count) { | ||
return geojsonRandom.polygon(count || 1).features; | ||
} | ||
test('DatasetClient', function(datasetClient) { | ||
@@ -247,30 +252,2 @@ | ||
datasetClient.test('#listFeatures', function(listFeatures) { | ||
listFeatures.test('typecheck', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
assert.throws(function() { | ||
client.deleteFeature([], function() {}); | ||
}, 'dataset must be a string'); | ||
assert.throws(function() { | ||
client.deleteFeature(''); | ||
}, 'callback must be a function'); | ||
assert.end(); | ||
}); | ||
listFeatures.test('valid request', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
client.listFeatures(testDatasets[0], function(err, collection) { | ||
assert.ifError(err, 'success'); | ||
assert.equal(geojsonhint(collection).length, 0, 'receieved valid GeoJSON'); | ||
assert.equal(collection.features.length, 1, 'one feature'); | ||
assert.equal(collection.features[0].id, testFeature, 'expected feature'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.end(); | ||
}); | ||
datasetClient.test('#deleteFeature', function(deleteFeature) { | ||
@@ -352,3 +329,3 @@ deleteFeature.test('typecheck', function(assert) { | ||
assert.ok(client, 'created dataset client'); | ||
var features = [randomFeature(), randomFeature(), randomFeature()].map(function(f) { | ||
var features = randomFeatures(3).map(function(f) { | ||
f.id = hat(); | ||
@@ -405,2 +382,101 @@ featureIds.push(f.id); | ||
datasetClient.test('#listFeatures', function(listFeatures) { | ||
listFeatures.test('insert some', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
var features = randomFeatures(3).map(function(f, i) { | ||
f.id = 'feature-' + i; | ||
return f; | ||
}); | ||
client.bulkFeatureUpdate({ put: features }, testDatasets[1], function(err, response) { | ||
assert.ifError(err, 'success'); | ||
assert.equal(response.put.length, 3, 'returned three features'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.test('typecheck', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
assert.throws(function() { | ||
client.listFeatures([], function() {}); | ||
}, 'dataset must be a string'); | ||
assert.throws(function() { | ||
client.listFeatures([], '', function() {}); | ||
}, 'options must be a object'); | ||
assert.throws(function() { | ||
client.listFeatures(''); | ||
}, 'callback must be a function'); | ||
assert.throws(function() { | ||
client.listFeatures([], { | ||
reverse: '' | ||
}, function() {}); | ||
}, 'reverse option must be a boolean'); | ||
assert.throws(function() { | ||
client.listFeatures([], { | ||
limit: '' | ||
}, function() {}); | ||
}, 'limit option must be a number'); | ||
assert.throws(function() { | ||
client.listFeatures([], { | ||
start: true | ||
}, function() {}); | ||
}, 'start option must be a string'); | ||
assert.end(); | ||
}); | ||
listFeatures.test('valid request', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
client.listFeatures(testDatasets[1], function(err, collection) { | ||
assert.ifError(err, 'success'); | ||
assert.equal(geojsonhint(collection).length, 0, 'receieved valid GeoJSON'); | ||
assert.equal(collection.features.length, 3, 'returned three features'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.test('options.limit', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
client.listFeatures(testDatasets[1], { | ||
limit: 1 | ||
}, function(err, collection) { | ||
assert.ifError(err, 'success'); | ||
assert.equal(collection.features.length, 1, 'returned one feature'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.test('options.start', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
client.listFeatures(testDatasets[1], { | ||
start: 'feature-1' | ||
}, function(err, collection) { | ||
assert.ifError(err, 'success'); | ||
assert.equal(collection.features.length, 1, 'returned one feature'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.test('options.reverse', function(assert) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
assert.ok(client, 'created dataset client'); | ||
client.listFeatures(testDatasets[1], { | ||
reverse: true | ||
}, function(err, collection) { | ||
assert.ifError(err, 'success'); | ||
var ids = collection.features.reduce(function(memo, feature) { | ||
memo.push(feature.id); | ||
return memo; | ||
}, []); | ||
assert.deepEqual(ids, ['feature-0', 'feature-1', 'feature-2'], 'features received in reverse order'); | ||
assert.end(); | ||
}); | ||
}); | ||
listFeatures.end(); | ||
}); | ||
datasetClient.test('#deleteDataset', function(deleteDataset) { | ||
@@ -407,0 +483,0 @@ deleteDataset.test('typecheck', function(assert) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
286212
5919
4
97