-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93bafe7
commit d92c97d
Showing
6 changed files
with
291 additions
and
0 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
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
148 changes: 148 additions & 0 deletions
148
lib/commercetools-api/src/Client/Resource/ByProjectKeyProductTailoringHead.php
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,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file has been auto generated | ||
* Do not change it. | ||
*/ | ||
|
||
namespace Commercetools\Api\Client\Resource; | ||
|
||
use Commercetools\Api\Models\Error\ErrorResponse; | ||
use Commercetools\Api\Models\Error\ErrorResponseModel; | ||
use Commercetools\Base\JsonObject; | ||
use Commercetools\Base\JsonObjectModel; | ||
use Commercetools\Client\ApiRequest; | ||
use Commercetools\Exception\ApiClientException; | ||
use Commercetools\Exception\ApiServerException; | ||
use Commercetools\Exception\ExceptionFactory; | ||
use Commercetools\Exception\InvalidArgumentException; | ||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Exception\RequestException; | ||
use GuzzleHttp\Exception\ServerException; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
* @template-implements Errorable<ByProjectKeyProductTailoringHead> | ||
* @template-implements Deprecatable200<ByProjectKeyProductTailoringHead> | ||
*/ | ||
class ByProjectKeyProductTailoringHead extends ApiRequest implements Errorable, Deprecatable200 | ||
{ | ||
/** | ||
* @param ?object|array|string $body | ||
* @psalm-param array<string, scalar|scalar[]> $headers | ||
*/ | ||
public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null) | ||
{ | ||
$uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/product-tailoring'); | ||
parent::__construct($client, 'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* @return ErrorResponse|JsonObject|T|null | ||
*/ | ||
public function mapFromResponse(?ResponseInterface $response, string $resultType = null) | ||
{ | ||
if (is_null($response)) { | ||
return null; | ||
} | ||
if (is_null($resultType)) { | ||
switch ($response->getStatusCode()) { | ||
case '400': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
case '401': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
case '403': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
case '500': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
case '502': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
case '503': | ||
$resultType = ErrorResponseModel::class; | ||
|
||
break; | ||
default: | ||
$resultType = JsonObjectModel::class; | ||
|
||
break; | ||
} | ||
} | ||
|
||
return $resultType::of($this->responseData($response)); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* | ||
* @return null|T|ErrorResponse|JsonObject | ||
*/ | ||
public function execute(array $options = [], string $resultType = null) | ||
{ | ||
try { | ||
$response = $this->send($options); | ||
} catch (ServerException $e) { | ||
$response = $e->getResponse(); | ||
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
throw $e; | ||
} catch (ClientException $e) { | ||
$response = $e->getResponse(); | ||
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
throw $e; | ||
} | ||
|
||
return $this->mapFromResponse($response, $resultType); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* | ||
* @return PromiseInterface | ||
*/ | ||
public function executeAsync(array $options = [], string $resultType = null) | ||
{ | ||
return $this->sendAsync($options)->then( | ||
function (ResponseInterface $response) use ($resultType) { | ||
return $this->mapFromResponse($response, $resultType); | ||
}, | ||
function (RequestException $e) use ($resultType) { | ||
$response = $e->getResponse(); | ||
if ($e instanceof ServerException) { | ||
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
} | ||
if ($e instanceof ClientException) { | ||
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
} | ||
throw $e; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* | ||
* @psalm-param scalar|scalar[] $where | ||
*/ | ||
public function withWhere($where): ByProjectKeyProductTailoringHead | ||
{ | ||
return $this->withQueryParam('where', $where); | ||
} | ||
} |
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