|
1 | 1 | function Requests(uber) {
|
2 |
| - this._uber = uber; |
3 |
| - this.path = 'requests'; |
| 2 | + this._uber = uber; |
| 3 | + this.path = 'requests'; |
4 | 4 |
|
5 |
| - // deprecated |
6 |
| - this.requestRide = this._uber.deprecateMethod(function requestRide(parameters, callback) { |
7 |
| - return this.create(parameters, callback); |
8 |
| - }, this.path + '.requestRide', this.path + '.create'); |
| 5 | + // deprecated |
| 6 | + this.requestRide = this._uber.deprecateMethod(function requestRide(parameters, callback) { |
| 7 | + return this.create(parameters, callback); |
| 8 | + }, this.path + '.requestRide', this.path + '.create'); |
9 | 9 |
|
10 |
| - this.estimate = this._uber.deprecateMethod(function estimate(parameters, callback) { |
11 |
| - return this.getEstimates(parameters, callback); |
12 |
| - }, this.path + '.estimate', this.path + '.getEstimates'); |
| 10 | + this.estimate = this._uber.deprecateMethod(function estimate(parameters, callback) { |
| 11 | + return this.getEstimates(parameters, callback); |
| 12 | + }, this.path + '.estimate', this.path + '.getEstimates'); |
13 | 13 | }
|
14 | 14 |
|
15 | 15 | module.exports = Requests;
|
16 | 16 |
|
17 | 17 | Requests.prototype.create = function create(parameters, callback) {
|
18 |
| - if (!parameters) { |
19 |
| - return callback(new Error('Invalid parameters')); |
20 |
| - } |
21 |
| - |
22 |
| - return this._uber.post({ url: this.path, params: parameters }, callback); |
| 18 | + if (!parameters) { |
| 19 | + return callback(new Error('Invalid parameters')); |
| 20 | + } |
| 21 | + |
| 22 | + return this._uber.post({ |
| 23 | + url: this.path, |
| 24 | + params: parameters |
| 25 | + }, callback); |
23 | 26 | };
|
24 | 27 |
|
25 | 28 | Requests.prototype.getCurrent = function getCurrent(callback) {
|
26 |
| - return this.getByID('current', callback); |
| 29 | + return this.getByID('current', callback); |
27 | 30 | };
|
28 | 31 |
|
29 | 32 | Requests.prototype.getByID = function getByID(id, callback) {
|
30 |
| - if (!id) { |
31 |
| - return callback(new Error('Invalid request_id')); |
32 |
| - } |
| 33 | + if (!id) { |
| 34 | + return callback(new Error('Invalid request_id')); |
| 35 | + } |
33 | 36 |
|
34 |
| - return this._uber.get({ url: this.path + '/' + id }, callback); |
| 37 | + return this._uber.get({ |
| 38 | + url: this.path + '/' + id |
| 39 | + }, callback); |
35 | 40 | };
|
36 | 41 |
|
37 | 42 | Requests.prototype.getMapByID = function getMapByID(id, callback) {
|
38 |
| - if (!id) { |
39 |
| - return callback(new Error('Invalid request_id')); |
40 |
| - } |
| 43 | + if (!id) { |
| 44 | + return callback(new Error('Invalid request_id')); |
| 45 | + } |
41 | 46 |
|
42 |
| - return this._uber.get({ url: this.path + '/' + id + '/map'}, callback); |
| 47 | + return this._uber.get({ |
| 48 | + url: this.path + '/' + id + '/map' |
| 49 | + }, callback); |
43 | 50 | };
|
44 | 51 |
|
45 | 52 | Requests.prototype.getReceiptByID = function getReceiptByID(id, callback) {
|
46 |
| - if (!id) { |
47 |
| - return callback(new Error('Invalid request_id')); |
48 |
| - } |
| 53 | + if (!id) { |
| 54 | + return callback(new Error('Invalid request_id')); |
| 55 | + } |
49 | 56 |
|
50 |
| - return this._uber.get({ url: this.path + '/' + id + '/receipt' }, callback); |
| 57 | + return this._uber.get({ |
| 58 | + url: this.path + '/' + id + '/receipt' |
| 59 | + }, callback); |
51 | 60 | };
|
52 | 61 |
|
53 | 62 | Requests.prototype.updateCurrent = function updateCurrent(parameters, callback) {
|
54 |
| - if (!parameters) { |
55 |
| - return callback(new Error('Invalid parameters')); |
56 |
| - } |
| 63 | + if (!parameters) { |
| 64 | + return callback(new Error('Invalid parameters')); |
| 65 | + } |
57 | 66 |
|
58 |
| - return this.updateByID('current', parameters, callback); |
| 67 | + return this.updateByID('current', parameters, callback); |
59 | 68 | };
|
60 | 69 |
|
61 | 70 | Requests.prototype.updateByID = function updateByID(id, parameters, callback) {
|
62 |
| - if (!id) { |
63 |
| - return callback(new Error('Invalid request_id')); |
64 |
| - } |
65 |
| - |
66 |
| - if (!parameters) { |
67 |
| - return callback(new Error('Invalid parameters')); |
68 |
| - } |
69 |
| - |
70 |
| - return this._uber.patch({ url: this.path + '/' + id, params: parameters }, callback); |
| 71 | + if (!id) { |
| 72 | + return callback(new Error('Invalid request_id')); |
| 73 | + } |
| 74 | + |
| 75 | + if (!parameters) { |
| 76 | + return callback(new Error('Invalid parameters')); |
| 77 | + } |
| 78 | + |
| 79 | + return this._uber.patch({ |
| 80 | + url: this.path + '/' + id, |
| 81 | + params: parameters |
| 82 | + }, callback); |
71 | 83 | };
|
72 | 84 |
|
73 | 85 | Requests.prototype.setStatusByID = function setStatusByID(id, newSatus, callback) {
|
74 |
| - if(!this._uber.sandbox) { |
75 |
| - return callback(new Error('PUT method for requests is only allowed in Sandbox mode')); |
76 |
| - } |
77 |
| - |
78 |
| - if (!id) { |
79 |
| - return callback(new Error('Invalid request_id')); |
80 |
| - } |
81 |
| - |
82 |
| - if (!newSatus) { |
83 |
| - return callback(new Error('Invalid status')); |
84 |
| - } |
85 |
| - |
86 |
| - return this._uber.put({ url: this.path + '/' + id, params: { status: newSatus } }, callback); |
| 86 | + if (!this._uber.sandbox) { |
| 87 | + return callback(new Error('PUT method for requests is only allowed in Sandbox mode')); |
| 88 | + } |
| 89 | + |
| 90 | + if (!id) { |
| 91 | + return callback(new Error('Invalid request_id')); |
| 92 | + } |
| 93 | + |
| 94 | + if (!newSatus) { |
| 95 | + return callback(new Error('Invalid status')); |
| 96 | + } |
| 97 | + |
| 98 | + return this._uber.put({ |
| 99 | + // this is required only for the PUT method |
| 100 | + url: 'sandbox/' + this.path + '/' + id, |
| 101 | + params: { |
| 102 | + status: newSatus |
| 103 | + } |
| 104 | + }, |
| 105 | + callback); |
87 | 106 | };
|
88 | 107 |
|
89 | 108 | Requests.prototype.deleteCurrent = function deleteCurrent(callback) {
|
90 |
| - return this.deleteByID('current', callback); |
| 109 | + return this.deleteByID('current', callback); |
91 | 110 | };
|
92 | 111 |
|
93 | 112 | Requests.prototype.deleteByID = function deleteByID(id, callback) {
|
94 |
| - if (!id) { |
95 |
| - return callback(new Error('Invalid request_id')); |
96 |
| - } |
| 113 | + if (!id) { |
| 114 | + return callback(new Error('Invalid request_id')); |
| 115 | + } |
97 | 116 |
|
98 |
| - return this._uber.delete({ url: this.path + '/' + id }, callback); |
| 117 | + return this._uber.delete({ |
| 118 | + url: this.path + '/' + id |
| 119 | + }, callback); |
99 | 120 | };
|
100 | 121 |
|
101 | 122 | Requests.prototype.getEstimates = function getEstimates(parameters, callback) {
|
102 |
| - if (!parameters) { |
103 |
| - return callback(new Error('Invalid parameters')); |
104 |
| - } |
105 |
| - |
106 |
| - return this._uber.post({ |
107 |
| - url: this.path + '/estimate', arams: parameters }, callback); |
| 123 | + if (!parameters) { |
| 124 | + return callback(new Error('Invalid parameters')); |
| 125 | + } |
| 126 | + |
| 127 | + return this._uber.post({ |
| 128 | + url: this.path + '/estimate', |
| 129 | + arams: parameters |
| 130 | + }, callback); |
108 | 131 | };
|
0 commit comments