1 | <?php namespace Stevenmaguire\Uber; |
||
8 | class Client |
||
9 | { |
||
10 | use GetSetTrait; |
||
11 | use Resources\Estimates; |
||
12 | use Resources\Products; |
||
13 | use Resources\Promotions; |
||
14 | use Resources\Reminders; |
||
15 | use Resources\Requests; |
||
16 | use Resources\Riders; |
||
17 | |||
18 | /** |
||
19 | * Access token |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $access_token; |
||
24 | |||
25 | /** |
||
26 | * Server token |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $server_token; |
||
31 | |||
32 | /** |
||
33 | * Use sandbox API |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $use_sandbox; |
||
38 | |||
39 | /** |
||
40 | * Version |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $version; |
||
45 | |||
46 | /** |
||
47 | * Locale |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $locale; |
||
52 | |||
53 | /** |
||
54 | * Rate limit |
||
55 | * |
||
56 | * @var RateLimit |
||
57 | */ |
||
58 | private $rate_limit = null; |
||
59 | |||
60 | /** |
||
61 | * Http client |
||
62 | * |
||
63 | * @var HttpClient |
||
64 | */ |
||
65 | private $http_client; |
||
66 | |||
67 | /** |
||
68 | * Create new client |
||
69 | * |
||
70 | * @param array $configuration |
||
71 | */ |
||
72 | 94 | public function __construct($configuration = []) |
|
78 | |||
79 | /** |
||
80 | * Apply configuration |
||
81 | * |
||
82 | * @param array $configuration |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | private function applyConfiguration($configuration = []) |
||
92 | |||
93 | /** |
||
94 | * Get authorization header value |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 72 | private function getAuthorizationHeader() |
|
106 | |||
107 | /** |
||
108 | * Get HttpClient config for verb and parameters |
||
109 | * |
||
110 | * @param string $verb |
||
111 | * @param array $parameters |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | 62 | private function getConfigForVerbAndParameters($verb, $parameters = []) |
|
131 | |||
132 | /** |
||
133 | * Get headers for request |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 72 | public function getHeaders() |
|
144 | |||
145 | /** |
||
146 | * Build url |
||
147 | * |
||
148 | * @param string $path |
||
149 | * |
||
150 | * @return string Url |
||
151 | */ |
||
152 | 66 | public function getUrlFromPath($path) |
|
160 | |||
161 | /** |
||
162 | * Handle http client exceptions |
||
163 | * |
||
164 | * @param HttpClientException $e |
||
165 | * |
||
166 | * @return void |
||
167 | * @throws Exception |
||
168 | */ |
||
169 | 6 | private function handleRequestException(HttpClientException $e) |
|
180 | |||
181 | /** |
||
182 | * Parse configuration using defaults |
||
183 | * |
||
184 | * @param array $configuration |
||
185 | * |
||
186 | * @return array $configuration |
||
187 | */ |
||
188 | 94 | private function parseConfiguration($configuration = []) |
|
200 | |||
201 | /** |
||
202 | * Attempt to pull rate limit headers from response and add to client |
||
203 | * |
||
204 | * @param Response $response |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | 56 | private function parseRateLimitFromResponse(Response $response) |
|
221 | |||
222 | /** |
||
223 | * Makes a request to the Uber API and returns the response |
||
224 | * |
||
225 | * @param string $verb The Http verb to use |
||
226 | * @param string $path The path of the APi after the domain |
||
227 | * @param array $parameters Parameters |
||
228 | * |
||
229 | * @return stdClass The JSON response from the request |
||
230 | * @throws Exception |
||
231 | */ |
||
232 | 62 | private function request($verb, $path, $parameters = []) |
|
249 | |||
250 | /** |
||
251 | * Set Http Client |
||
252 | * |
||
253 | * @param HttpClient $client |
||
254 | * |
||
255 | * @return Client |
||
256 | */ |
||
257 | 62 | public function setHttpClient(HttpClient $client) |
|
262 | |||
263 | /** |
||
264 | * Throws exception when client is not configured sandbox use. Should only |
||
265 | * be utilized when attempting to do work against ephemeral sandbox API |
||
266 | * data. |
||
267 | * |
||
268 | * @see https://developer.uber.com/docs/riders/guides/sandbox |
||
269 | * @return void |
||
270 | * @throws Exception |
||
271 | */ |
||
272 | 8 | private function enforceSandboxExpectation($message = null) |
|
280 | } |
||
281 |