Skip to content

Commit bc7042c

Browse files
committed
1 parent fdfc656 commit bc7042c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/Adapter/Guzzle.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,31 @@ public function request(string $method, string $uri, array $data = [], array $he
8080
}
8181

8282
try {
83-
$response = $this->client->$method($uri, [
84-
'headers' => $headers,
85-
($method === 'get' ? 'query' : 'json') => $data,
86-
]);
83+
$methodData = $this->getMethodData($method, $data);
84+
$response = $this->client->$method($uri, ['headers' => $headers] + $methodData);
8785
} catch (RequestException $err) {
8886
throw ResponseException::fromRequestException($err);
8987
}
9088

9189
return $response;
9290
}
91+
92+
/**
93+
* Gets the data for the request as per the method.
94+
* @param string $method
95+
* @param array $data
96+
* @return array|array[]
97+
*/
98+
public function getMethodData(string $method, array $data): array
99+
{
100+
if ($method === 'get') {
101+
return ['query' => $data];
102+
}
103+
104+
if (array_key_exists('multipart', $data)) {
105+
return $data;
106+
}
107+
108+
return ['json' => $data];
109+
}
93110
}

0 commit comments

Comments
 (0)