43 public function __construct(
string $projectKey, $body =
null, array $headers = [], ClientInterface $client =
null)
45 $uri = str_replace([
'{projectKey}'], [$projectKey],
'{projectKey}/stores');
46 parent::__construct($client,
'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
54 public function mapFromResponse(?ResponseInterface $response,
string $resultType =
null)
56 if (is_null($response)) {
59 if (is_null($resultType)) {
60 switch ($response->getStatusCode()) {
62 $resultType = StoreModel::class;
66 $resultType = ErrorResponseModel::class;
70 $resultType = ErrorResponseModel::class;
74 $resultType = ErrorResponseModel::class;
78 $resultType = ErrorResponseModel::class;
82 $resultType = ErrorResponseModel::class;
86 $resultType = ErrorResponseModel::class;
90 $resultType = JsonObjectModel::class;
105 public function execute(array $options = [],
string $resultType =
null)
108 $response = $this->
send($options);
109 }
catch (ServerException $e) {
110 $response = $e->getResponse();
111 $e = ExceptionFactory::createServerException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
113 }
catch (ClientException $e) {
114 $response = $e->getResponse();
115 $e = ExceptionFactory::createClientException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
128 public function executeAsync(array $options = [],
string $resultType =
null)
131 function (ResponseInterface $response) use ($resultType) {
134 function (RequestException $e) use ($resultType) {
135 $response = $e->getResponse();
136 if ($e instanceof ServerException) {
137 $e = ExceptionFactory::createServerException($e, $this, $response, $this->
mapFromResponse($response, $resultType));
139 if ($e instanceof ClientException) {
140 $e = ExceptionFactory::createClientException($e, $this, $response, $this->
mapFromResponse($response, $resultType));