@@ -27,33 +27,33 @@ |
||
27 | 27 | * MethodNotAllowedException|NotFoundException|RateLimitExceededException|UnsupportedAcceptHeaderException| |
28 | 28 | * UnsupportedContentTypeException|ValidationException |
29 | 29 | */ |
30 | - public static function create(RequestException $e) { |
|
30 | + public static function create(RequestException $e) { |
|
31 | 31 | |
32 | - if($response = $e->getResponse()) { |
|
32 | + if($response = $e->getResponse()) { |
|
33 | 33 | |
34 | - switch ($response->getStatusCode()) { |
|
35 | - case 400: |
|
34 | + switch ($response->getStatusCode()) { |
|
35 | + case 400: |
|
36 | 36 | return new ValidationException($e); |
37 | - case 401: |
|
37 | + case 401: |
|
38 | 38 | return new AuthenticationException($e); |
39 | - case 403: |
|
39 | + case 403: |
|
40 | 40 | return new AccessDeniedException($e); |
41 | - case 404: |
|
41 | + case 404: |
|
42 | 42 | return new NotFoundException($e); |
43 | - case 405: |
|
43 | + case 405: |
|
44 | 44 | return new MethodNotAllowedException($e); |
45 | - case 406: |
|
45 | + case 406: |
|
46 | 46 | return new UnsupportedAcceptHeaderException($e); |
47 | - case 409: |
|
47 | + case 409: |
|
48 | 48 | return new ConflictingStateException($e); |
49 | - case 415: |
|
49 | + case 415: |
|
50 | 50 | return new UnsupportedContentTypeException($e); |
51 | - case 429: |
|
51 | + case 429: |
|
52 | 52 | return new RateLimitExceededException($e); |
53 | - } |
|
54 | - } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - return new ApiException($e); |
|
56 | + return new ApiException($e); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -29,7 +29,7 @@ |
||
29 | 29 | */ |
30 | 30 | public static function create(RequestException $e) { |
31 | 31 | |
32 | - if($response = $e->getResponse()) { |
|
32 | + if ($response = $e->getResponse()) { |
|
33 | 33 | |
34 | 34 | switch ($response->getStatusCode()) { |
35 | 35 | case 400: |
@@ -152,9 +152,9 @@ |
||
152 | 152 | */ |
153 | 153 | public function search(string $filtersQuery) |
154 | 154 | { |
155 | - $end = '/search'.$this->endpoint(); |
|
155 | + $end = '/search' . $this->endpoint(); |
|
156 | 156 | $query = [ |
157 | - 'query' => '"'.$filtersQuery.'"', |
|
157 | + 'query' => '"' . $filtersQuery . '"', |
|
158 | 158 | ]; |
159 | 159 | return $this->api()->request('GET', $end, null, $query); |
160 | 160 | } |
@@ -217,39 +217,39 @@ |
||
217 | 217 | public function request($method, $endpoint, array $data = null, array $query = null) |
218 | 218 | { |
219 | 219 | |
220 | - if (isset($data['attachments'])) { |
|
221 | - // Has file attachments, so we can't use the json property. |
|
222 | - // Instead, we have to use the "multipart" property |
|
223 | - $attachments = $data['attachments']; |
|
224 | - unset($data['attachments']); |
|
225 | - |
|
226 | - if (!is_array($attachments)) { |
|
227 | - $attachments = [$attachments]; |
|
228 | - } |
|
229 | - |
|
230 | - $multiparts = []; |
|
231 | - foreach($attachments as $attachment) { |
|
232 | - $multiparts[] = [ |
|
233 | - 'name' => 'attachments[]', |
|
234 | - 'contents' => $attachment, // $attachment is a resource from fopen('/path/to/file', 'r') |
|
235 | - ]; |
|
236 | - } |
|
237 | - foreach($data as $key => $value) { |
|
238 | - $multiparts[] = [ |
|
239 | - 'name' => $key, |
|
240 | - 'contents' => $value, |
|
241 | - ]; |
|
242 | - } |
|
243 | - |
|
244 | - $options = [ |
|
245 | - 'multipart' => $multiparts, |
|
246 | - ]; |
|
247 | - } else { |
|
248 | - // normal method |
|
249 | - $options = [ |
|
250 | - 'json' => $data, |
|
251 | - ]; |
|
252 | - } |
|
220 | + if (isset($data['attachments'])) { |
|
221 | + // Has file attachments, so we can't use the json property. |
|
222 | + // Instead, we have to use the "multipart" property |
|
223 | + $attachments = $data['attachments']; |
|
224 | + unset($data['attachments']); |
|
225 | + |
|
226 | + if (!is_array($attachments)) { |
|
227 | + $attachments = [$attachments]; |
|
228 | + } |
|
229 | + |
|
230 | + $multiparts = []; |
|
231 | + foreach($attachments as $attachment) { |
|
232 | + $multiparts[] = [ |
|
233 | + 'name' => 'attachments[]', |
|
234 | + 'contents' => $attachment, // $attachment is a resource from fopen('/path/to/file', 'r') |
|
235 | + ]; |
|
236 | + } |
|
237 | + foreach($data as $key => $value) { |
|
238 | + $multiparts[] = [ |
|
239 | + 'name' => $key, |
|
240 | + 'contents' => $value, |
|
241 | + ]; |
|
242 | + } |
|
243 | + |
|
244 | + $options = [ |
|
245 | + 'multipart' => $multiparts, |
|
246 | + ]; |
|
247 | + } else { |
|
248 | + // normal method |
|
249 | + $options = [ |
|
250 | + 'json' => $data, |
|
251 | + ]; |
|
252 | + } |
|
253 | 253 | |
254 | 254 | if (isset($query)) { |
255 | 255 | $options['query'] = $query; |
@@ -228,13 +228,13 @@ |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | $multiparts = []; |
231 | - foreach($attachments as $attachment) { |
|
231 | + foreach ($attachments as $attachment) { |
|
232 | 232 | $multiparts[] = [ |
233 | 233 | 'name' => 'attachments[]', |
234 | 234 | 'contents' => $attachment, // $attachment is a resource from fopen('/path/to/file', 'r') |
235 | 235 | ]; |
236 | 236 | } |
237 | - foreach($data as $key => $value) { |
|
237 | + foreach ($data as $key => $value) { |
|
238 | 238 | $multiparts[] = [ |
239 | 239 | 'name' => $key, |
240 | 240 | 'contents' => $value, |