Add method to retrieve the Guzzle client

This commit is contained in:
Andrea Marco Sartori 2023-06-13 17:08:58 +02:00
parent 5a65884255
commit eee0e8bc63

View File

@ -45,7 +45,7 @@ trait GuzzleAware
*/
protected function getJson(UriInterface|string $url): ResponseInterface
{
return (new Client())->get($url, [
return $this->guzzle()->get($url, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
@ -53,6 +53,16 @@ trait GuzzleAware
]);
}
/**
* Retrieve the Guzzle client
*
* @return Client
*/
protected function guzzle(): Client
{
return new Client();
}
/**
* Retrieve the JSON response of the given request
*
@ -61,6 +71,6 @@ trait GuzzleAware
*/
protected function sendRequest(RequestInterface $request): ResponseInterface
{
return (new Client())->sendRequest($request);
return $this->guzzle()->sendRequest($request);
}
}