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}');
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 = ProjectModel::class;
64 $resultType = ErrorResponseModel::class;
68 $resultType = JsonObjectModel::class;
83 public function execute(array $options = [],
string $resultType =
null)
86 $response = $this->
send($options);
87 }
catch (ServerException $e) {
88 $response = $e->getResponse();
91 }
catch (ClientException $e) {
92 $response = $e->getResponse();
106 public function executeAsync(array $options = [],
string $resultType =
null)
109 function (ResponseInterface $response) use ($resultType) {
112 function (RequestException $e) use ($resultType) {
113 $response = $e->getResponse();
114 if ($e instanceof ServerException) {
117 if ($e instanceof ClientException) {
executeAsync(array $options=[], string $resultType=null)
__construct(string $projectKey, $body=null, array $headers=[], ClientInterface $client=null)
mapFromResponse(?ResponseInterface $response, string $resultType=null)
execute(array $options=[], string $resultType=null)