@@ -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, |