1
|
|
|
<?php namespace Stevenmaguire\Uber\Resources; |
2
|
|
|
|
3
|
|
|
trait Requests |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* Cancels the current ride request. |
7
|
|
|
* |
8
|
|
|
* @return stdClass The JSON response from the request |
9
|
|
|
* |
10
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-delete |
11
|
|
|
*/ |
12
|
2 |
|
public function cancelCurrentRequest() |
13
|
|
|
{ |
14
|
2 |
|
return $this->cancelRequest('current'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Cancels a specific ride request. |
19
|
|
|
* |
20
|
|
|
* @param string $requestId Request id |
21
|
|
|
* |
22
|
|
|
* @return stdClass The JSON response from the request |
23
|
|
|
* |
24
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-delete |
25
|
|
|
*/ |
26
|
4 |
|
public function cancelRequest($requestId) |
27
|
|
|
{ |
28
|
4 |
|
return $this->request('delete', 'requests/'.$requestId); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Fetches the current ride request. |
33
|
|
|
* |
34
|
|
|
* The Ride Request endpoint allows retrieving real-time details for an |
35
|
|
|
* ongoing trip. |
36
|
|
|
* |
37
|
|
|
* This endpoint behaves similarly to the GET /requests/{request_id} |
38
|
|
|
* endpoint, except you do not need to provide a request_id. If there is |
39
|
|
|
* no trip in progress the endpoint will result in a 404 not found error. |
40
|
|
|
* This endpoint will only work for trips requested through your app unless |
41
|
|
|
* you have the all_trips scope. |
42
|
|
|
* |
43
|
|
|
* By default, only details about trips your app requested will be returned. |
44
|
|
|
* If your app has all_trips scope, however, trip details will be returned |
45
|
|
|
* for all trips irrespective of which application initiated them. |
46
|
|
|
* |
47
|
|
|
* See the Ride Request tutorial for a step-by-step guide to requesting |
48
|
|
|
* rides on behalf of an Uber user. Please review the Sandbox documentation |
49
|
|
|
* on how to develop and test against these endpoints without making |
50
|
|
|
* real-world Ride Requests and being charged. |
51
|
|
|
* |
52
|
|
|
* @return stdClass The JSON response from the request |
53
|
|
|
* |
54
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-get |
55
|
|
|
*/ |
56
|
2 |
|
public function getCurrentRequest() |
57
|
|
|
{ |
58
|
2 |
|
return $this->getRequest('current'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Fetches a specific ride request. |
63
|
|
|
* |
64
|
|
|
* @param string $requestId Request id |
65
|
|
|
* |
66
|
|
|
* @return stdClass The JSON response from the request |
67
|
|
|
* |
68
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-get |
69
|
|
|
*/ |
70
|
4 |
|
public function getRequest($requestId) |
71
|
|
|
{ |
72
|
4 |
|
return $this->request('get', 'requests/'.$requestId); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Creates a ride request estimate. |
77
|
|
|
* |
78
|
|
|
* The Request Estimate endpoint allows a ride to be estimated given the |
79
|
|
|
* desired product, start, and end locations. If the end location is |
80
|
|
|
* not provided, only the pickup ETA and details of surge pricing |
81
|
|
|
* information are provided. If the pickup ETA is null, there are no cars |
82
|
|
|
* available, but an estimate may still be given to the user. |
83
|
|
|
* |
84
|
|
|
* @param array $attributes Query attributes |
85
|
|
|
* |
86
|
|
|
* @return stdClass The JSON response from the request |
87
|
|
|
* |
88
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-estimate-post |
89
|
|
|
*/ |
90
|
2 |
|
public function getRequestEstimate($attributes = []) |
91
|
|
|
{ |
92
|
2 |
|
return $this->request('post', 'requests/estimate', $attributes); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Fetches the map for a specific ride request. |
97
|
|
|
* |
98
|
|
|
* @param string $requestId Request id |
99
|
|
|
* |
100
|
|
|
* @return stdClass The JSON response from the request |
101
|
|
|
* |
102
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-map-get |
103
|
|
|
*/ |
104
|
2 |
|
public function getRequestMap($requestId) |
105
|
|
|
{ |
106
|
2 |
|
return $this->request('get', 'requests/'.$requestId.'/map'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Fetches the receipt for a specific ride request. |
111
|
|
|
* |
112
|
|
|
* @param string $requestId Request id |
113
|
|
|
* |
114
|
|
|
* @return stdClass The JSON response from the request |
115
|
|
|
* |
116
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-receipt-get |
117
|
|
|
*/ |
118
|
2 |
|
public function getRequestReceipt($requestId) |
119
|
|
|
{ |
120
|
2 |
|
return $this->request('get', 'requests/'.$requestId.'/receipt'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Makes a request to the Uber API and returns the response. |
125
|
|
|
* |
126
|
|
|
* @param string $verb The Http verb to use |
127
|
|
|
* @param string $path The path of the APi after the domain |
128
|
|
|
* @param array $parameters Parameters |
129
|
|
|
* |
130
|
|
|
* @return stdClass The JSON response from the request |
131
|
|
|
* @throws Exception |
132
|
|
|
*/ |
133
|
|
|
abstract protected function request($verb, $path, $parameters = []); |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Creates a new ride request. |
137
|
|
|
* |
138
|
|
|
* The Request endpoint allows a ride to be requested on behalf of an Uber |
139
|
|
|
* user given their desired product, start, and end locations. |
140
|
|
|
* |
141
|
|
|
* @param array $attributes Query attributes |
142
|
|
|
* |
143
|
|
|
* @return stdClass The JSON response from the request |
144
|
|
|
* |
145
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-post |
146
|
|
|
*/ |
147
|
2 |
|
public function requestRide($attributes = []) |
148
|
|
|
{ |
149
|
2 |
|
return $this->request('post', 'requests', $attributes); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Updates the current ride request. |
154
|
|
|
* |
155
|
|
|
* The Ride Request endpoint allows updating an ongoing request’s |
156
|
|
|
* destination. |
157
|
|
|
* |
158
|
|
|
* This endpoint behaves similarly to the PATCH /v1.2/requests/{request_id} |
159
|
|
|
* endpoint, except you do not need to provide a request_id. If there is no |
160
|
|
|
* trip in progress the endpoint will result in a 404 not found error. This |
161
|
|
|
* endpoint will only work for trips requested through your app unless you |
162
|
|
|
* have the all_trips scope. |
163
|
|
|
* |
164
|
|
|
* @param array $attributes Query attributes |
165
|
|
|
* |
166
|
|
|
* @return stdClass The JSON response from the request |
167
|
|
|
* |
168
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch |
169
|
|
|
*/ |
170
|
2 |
|
public function setCurrentRequest($attributes = []) |
171
|
|
|
{ |
172
|
2 |
|
return $this->setRequest('current', $attributes); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Updates a specific ride request. |
177
|
|
|
* |
178
|
|
|
* The Ride Request endpoint allows updating an ongoing request’s |
179
|
|
|
* destination using the Ride Request endpoint. |
180
|
|
|
* |
181
|
|
|
* @param string $requestId Request id |
182
|
|
|
* @param array $attributes Query attributes |
183
|
|
|
* |
184
|
|
|
* @return stdClass The JSON response from the request |
185
|
|
|
* |
186
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-patch |
187
|
|
|
*/ |
188
|
4 |
|
public function setRequest($requestId, $attributes = []) |
189
|
|
|
{ |
190
|
4 |
|
return $this->request('patch', 'requests/'.$requestId, $attributes); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Updates a specific ride request properties for sandbox responses. |
195
|
|
|
* |
196
|
|
|
* @param string $requestId Request id |
197
|
|
|
* @param array $attributes Query attributes |
198
|
|
|
* |
199
|
|
|
* @return stdClass The JSON response from the request |
200
|
|
|
* @throws Exception |
201
|
|
|
* |
202
|
|
|
* @see https://developer.uber.com/docs/riders/references/api/v1.2/requests-estimate-post |
203
|
|
|
*/ |
204
|
4 |
|
public function setSandboxRequest($requestId, $attributes = []) |
205
|
|
|
{ |
206
|
4 |
|
$this->enforceSandboxExpectation(); |
|
|
|
|
207
|
|
|
|
208
|
2 |
|
return $this->request('put', 'sandbox/requests/'.$requestId, $attributes); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.