From bc7042c561413b48e9d4def2919d976d356edf34 Mon Sep 17 00:00:00 2001 From: RSL Date: Thu, 14 Jul 2022 09:40:28 +0100 Subject: [PATCH] Fix for post-ing form data. https://api.cloudflare.com/#dns-records-for-a-zone-import-dns-records. Issue: https://github.com/cloudflare/cloudflare-php/issues/226 --- src/Adapter/Guzzle.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index 71e7dd75..5118d3c8 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -80,14 +80,31 @@ public function request(string $method, string $uri, array $data = [], array $he } try { - $response = $this->client->$method($uri, [ - 'headers' => $headers, - ($method === 'get' ? 'query' : 'json') => $data, - ]); + $methodData = $this->getMethodData($method, $data); + $response = $this->client->$method($uri, ['headers' => $headers] + $methodData); } catch (RequestException $err) { throw ResponseException::fromRequestException($err); } return $response; } + + /** + * Gets the data for the request as per the method. + * @param string $method + * @param array $data + * @return array|array[] + */ + public function getMethodData(string $method, array $data): array + { + if ($method === 'get') { + return ['query' => $data]; + } + + if (array_key_exists('multipart', $data)) { + return $data; + } + + return ['json' => $data]; + } }