Skip to content

Commit

Permalink
Fix for post-ing form data.
Browse files Browse the repository at this point in the history
  • Loading branch information
rslsystems committed Jul 14, 2022
1 parent fdfc656 commit bc7042c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Adapter/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

0 comments on commit bc7042c

Please sign in to comment.