diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index 71e7dd7..21c48ec 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -88,6 +88,34 @@ class Guzzle implements Adapter throw ResponseException::fromRequestException($err); } + return $response; + } + + /** + * @SuppressWarnings(PHPMD.StaticAccess) + */ + public function requestMultiPart(string $method, string $uri, array $data = [], array $headers = []) { + if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) { + throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete'); + } + + $multipart = []; + foreach( $data as $key => $value ) { + $multipart[] = [ + 'name' => $key, + 'contents' => $value + ]; + } + + try { + $response = $this->client->$method($uri, [ + 'headers' => $headers, + 'multipart' => $multipart + ]); + } catch (RequestException $err) { + throw ResponseException::fromRequestException($err); + } + return $response; } }