Skip to content

Commit

Permalink
Bug fix for #32
Browse files Browse the repository at this point in the history
Also updating the README and bumping up the version to 0.96
  • Loading branch information
agraebe committed May 25, 2016
1 parent 9840032 commit fc90880
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 72 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/resources/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand All @@ -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
},
Expand Down
151 changes: 87 additions & 64 deletions lib/resources/Requests.js
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions test/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fc90880

Please sign in to comment.