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();
89 $e = ExceptionFactory::createServerException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
91 }
catch (ClientException $e) {
92 $response = $e->getResponse();
93 $e = ExceptionFactory::createClientException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
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) {
115 $e = ExceptionFactory::createServerException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
117 if ($e instanceof ClientException) {
118 $e = ExceptionFactory::createClientException($e, $this, $response, $this->
mapFromResponse($response, $resultType));