3 declare(strict_types=1);
22 use GuzzleHttp\ClientInterface;
23 use GuzzleHttp\Exception\ClientException;
24 use GuzzleHttp\Exception\RequestException;
25 use GuzzleHttp\Exception\ServerException;
26 use GuzzleHttp\Promise\PromiseInterface;
28 use Psr\Http\Message\ResponseInterface;
41 public function __construct(
string $projectKey, $body =
null, array $headers = [], ClientInterface $client =
null)
43 $uri = str_replace([
'{projectKey}'], [$projectKey],
'{projectKey}/login');
44 parent::__construct($client,
'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
52 public function mapFromResponse(?ResponseInterface $response,
string $resultType =
null)
54 if (is_null($response)) {
57 if (is_null($resultType)) {
58 switch ($response->getStatusCode()) {
60 $resultType = CustomerSignInResultModel::class;
64 $resultType = ErrorResponseModel::class;
68 $resultType = ErrorResponseModel::class;
72 $resultType = ErrorResponseModel::class;
76 $resultType = ErrorResponseModel::class;
80 $resultType = ErrorResponseModel::class;
84 $resultType = ErrorResponseModel::class;
88 $resultType = JsonObjectModel::class;
103 public function execute(array $options = [],
string $resultType =
null)
106 $response = $this->
send($options);
107 }
catch (ServerException $e) {
108 $response = $e->getResponse();
111 }
catch (ClientException $e) {
112 $response = $e->getResponse();
126 public function executeAsync(array $options = [],
string $resultType =
null)
129 function (ResponseInterface $response) use ($resultType) {
132 function (RequestException $e) use ($resultType) {
133 $response = $e->getResponse();
134 if ($e instanceof ServerException) {
137 if ($e instanceof ClientException) {
execute(array $options=[], string $resultType=null)
__construct(string $projectKey, $body=null, array $headers=[], ClientInterface $client=null)
executeAsync(array $options=[], string $resultType=null)
mapFromResponse(?ResponseInterface $response, string $resultType=null)