diff --git a/README.md b/README.md index f27bc0b..68502f6 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ The history endpoint can be accessed ONLY with an OAuth ``access_token`` authori #### [Get user activity](https://developer.uber.com/docs/v12-history) ```javascript -uber.user.getHistory(offset, limit [, access_token], callback); +uber.user.getHistory(offset, limit, callback); ``` ``offset`` defaults to 0 and ``limit`` defaults to 5 with a maximum value of 50. @@ -296,7 +296,7 @@ uber.user.getHistory(0, 5, function(err, res) { The me endpoint can be accessed ONLY with an OAuth ``access_token`` authorized with the ``profile`` scope. #### [Get user profile](https://developer.uber.com/docs/v1-me) ```javascript -uber.user.getProfile([access_token], callback); +uber.user.getProfile(callback); ``` ##### Example diff --git a/lib/resources/Products.js b/lib/resources/Products.js index 8010b26..7c02ac5 100644 --- a/lib/resources/Products.js +++ b/lib/resources/Products.js @@ -46,7 +46,8 @@ Products.prototype.setSurgeMultiplierByID = function setSurgeMultiplierByID(id, return callback(new Error('Invalid surge multiplier')); } else { return this._uber.put({ - url: this.path + '/' + id, + // this is required only for the PUT method + url: 'sandbox/' + this.path + '/' + id, params: { surge_multiplier: parseFloat(multiplier) }, @@ -68,7 +69,8 @@ Products.prototype.setDriversAvailabilityByID = function setDriversAvailabilityB return callback(new Error('Availability needs to be a boolean')); } else { return this._uber.put({ - url: this.path + '/' + id, + // this is required only for the PUT method + url: 'sandbox/' + this.path + '/' + id, params: { drivers_available: availability }, diff --git a/lib/resources/Requests.js b/lib/resources/Requests.js index d3d7f33..9092023 100644 --- a/lib/resources/Requests.js +++ b/lib/resources/Requests.js @@ -1,108 +1,131 @@ function Requests(uber) { - this._uber = uber; - this.path = 'requests'; + this._uber = uber; + this.path = 'requests'; - // deprecated - this.requestRide = this._uber.deprecateMethod(function requestRide(parameters, callback) { - return this.create(parameters, callback); - }, this.path + '.requestRide', this.path + '.create'); + // deprecated + this.requestRide = this._uber.deprecateMethod(function requestRide(parameters, callback) { + return this.create(parameters, callback); + }, this.path + '.requestRide', this.path + '.create'); - this.estimate = this._uber.deprecateMethod(function estimate(parameters, callback) { - return this.getEstimates(parameters, callback); - }, this.path + '.estimate', this.path + '.getEstimates'); + this.estimate = this._uber.deprecateMethod(function estimate(parameters, callback) { + return this.getEstimates(parameters, callback); + }, this.path + '.estimate', this.path + '.getEstimates'); } module.exports = Requests; Requests.prototype.create = function create(parameters, callback) { - if (!parameters) { - return callback(new Error('Invalid parameters')); - } - - return this._uber.post({ url: this.path, params: parameters }, callback); + if (!parameters) { + return callback(new Error('Invalid parameters')); + } + + return this._uber.post({ + url: this.path, + params: parameters + }, callback); }; Requests.prototype.getCurrent = function getCurrent(callback) { - return this.getByID('current', callback); + return this.getByID('current', callback); }; Requests.prototype.getByID = function getByID(id, callback) { - if (!id) { - return callback(new Error('Invalid request_id')); - } + if (!id) { + return callback(new Error('Invalid request_id')); + } - return this._uber.get({ url: this.path + '/' + id }, callback); + return this._uber.get({ + url: this.path + '/' + id + }, callback); }; Requests.prototype.getMapByID = function getMapByID(id, callback) { - if (!id) { - return callback(new Error('Invalid request_id')); - } + if (!id) { + return callback(new Error('Invalid request_id')); + } - return this._uber.get({ url: this.path + '/' + id + '/map'}, callback); + return this._uber.get({ + url: this.path + '/' + id + '/map' + }, callback); }; Requests.prototype.getReceiptByID = function getReceiptByID(id, callback) { - if (!id) { - return callback(new Error('Invalid request_id')); - } + if (!id) { + return callback(new Error('Invalid request_id')); + } - return this._uber.get({ url: this.path + '/' + id + '/receipt' }, callback); + return this._uber.get({ + url: this.path + '/' + id + '/receipt' + }, callback); }; Requests.prototype.updateCurrent = function updateCurrent(parameters, callback) { - if (!parameters) { - return callback(new Error('Invalid parameters')); - } + if (!parameters) { + return callback(new Error('Invalid parameters')); + } - return this.updateByID('current', parameters, callback); + return this.updateByID('current', parameters, callback); }; Requests.prototype.updateByID = function updateByID(id, parameters, callback) { - if (!id) { - return callback(new Error('Invalid request_id')); - } - - if (!parameters) { - return callback(new Error('Invalid parameters')); - } - - return this._uber.patch({ url: this.path + '/' + id, params: parameters }, callback); + if (!id) { + return callback(new Error('Invalid request_id')); + } + + if (!parameters) { + return callback(new Error('Invalid parameters')); + } + + return this._uber.patch({ + url: this.path + '/' + id, + params: parameters + }, callback); }; Requests.prototype.setStatusByID = function setStatusByID(id, newSatus, callback) { - if(!this._uber.sandbox) { - return callback(new Error('PUT method for requests is only allowed in Sandbox mode')); - } - - if (!id) { - return callback(new Error('Invalid request_id')); - } - - if (!newSatus) { - return callback(new Error('Invalid status')); - } - - return this._uber.put({ url: this.path + '/' + id, params: { status: newSatus } }, callback); + if (!this._uber.sandbox) { + return callback(new Error('PUT method for requests is only allowed in Sandbox mode')); + } + + if (!id) { + return callback(new Error('Invalid request_id')); + } + + if (!newSatus) { + return callback(new Error('Invalid status')); + } + + return this._uber.put({ + // this is required only for the PUT method + url: 'sandbox/' + this.path + '/' + id, + params: { + status: newSatus + } + }, + callback); }; Requests.prototype.deleteCurrent = function deleteCurrent(callback) { - return this.deleteByID('current', callback); + return this.deleteByID('current', callback); }; Requests.prototype.deleteByID = function deleteByID(id, callback) { - if (!id) { - return callback(new Error('Invalid request_id')); - } + if (!id) { + return callback(new Error('Invalid request_id')); + } - return this._uber.delete({ url: this.path + '/' + id }, callback); + return this._uber.delete({ + url: this.path + '/' + id + }, callback); }; Requests.prototype.getEstimates = function getEstimates(parameters, callback) { - if (!parameters) { - return callback(new Error('Invalid parameters')); - } - - return this._uber.post({ - url: this.path + '/estimate', arams: parameters }, callback); + if (!parameters) { + return callback(new Error('Invalid parameters')); + } + + return this._uber.post({ + url: this.path + '/estimate', + arams: parameters + }, callback); }; diff --git a/package.json b/package.json index 81c6b62..0929a1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-uber", - "version": "0.9.5", + "version": "0.9.6", "description": "A Node.js wrapper for Uber API", "main": "index.js", "scripts": { diff --git a/test/products.js b/test/products.js index b22c1bd..0f8ca75 100644 --- a/test/products.js +++ b/test/products.js @@ -107,7 +107,7 @@ describe('Details', function() { describe('Set surge multiplier in Sandbox mode', function() { before(function() { nock('https://sandbox-api.uber.com/') - .put('/v1/products/d4abaae7-f4d6-4152-91cc-77523e8165a4', { + .put('/v1/sandbox/products/d4abaae7-f4d6-4152-91cc-77523e8165a4', { surge_multiplier: 2.2 }) .reply(204); @@ -145,7 +145,7 @@ describe('Set surge multiplier in Sandbox mode', function() { describe('Set driver`s availability in Sandbox mode', function() { before(function() { nock('https://sandbox-api.uber.com/') - .put('/v1/products/d4abaae7-f4d6-4152-91cc-77523e8165a4', { + .put('/v1/sandbox/products/d4abaae7-f4d6-4152-91cc-77523e8165a4', { drivers_available: false }) .reply(204); diff --git a/test/requests.js b/test/requests.js index 53aff05..14478f1 100644 --- a/test/requests.js +++ b/test/requests.js @@ -281,7 +281,7 @@ describe('By Request ID', function() { .times(2) .reply(204); nock('https://sandbox-api.uber.com/') - .put('/v1/requests/17cb78a7-b672-4d34-a288-a6c6e44d5315', { + .put('/v1/sandbox/requests/17cb78a7-b672-4d34-a288-a6c6e44d5315', { status: 'accepted' }) .reply(204);