-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also updating the README and bumping up the version to 0.96
- Loading branch information
Showing
6 changed files
with
97 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters