-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #232 Co-authored-by: Edie Lemoine <edie@myparcel.nl>
- Loading branch information
1 parent
3965452
commit 6554b5d
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Pdk\Api\Adapter; | ||
|
||
use GuzzleHttp\Client; | ||
use MyParcelNL\Pdk\Api\Contract\ClientAdapterInterface; | ||
use MyParcelNL\Pdk\Api\Contract\ClientResponseInterface; | ||
use MyParcelNL\Pdk\Api\Response\ClientResponse; | ||
|
||
class Guzzle5ClientAdapter implements ClientAdapterInterface | ||
{ | ||
/** | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param \GuzzleHttp\Client $client | ||
*/ | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* @param string $httpMethod | ||
* @param string $uri | ||
* @param array $options | ||
* | ||
* @return \MyParcelNL\Pdk\Api\Contract\ClientResponseInterface | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function doRequest(string $httpMethod, string $uri, array $options = []): ClientResponseInterface | ||
{ | ||
$clientRequest = $this->client->createRequest($httpMethod, $uri, $options); | ||
|
||
$clientResponse = $this->client->send($clientRequest); | ||
$statusCode = $clientResponse->getStatusCode() ?? 0; | ||
|
||
return new ClientResponse($clientResponse->getBody()->getContents(), $statusCode, $clientResponse->getHeaders()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters