From 3edb776e46c36f84b1e426452c6561fa8b0bf1a2 Mon Sep 17 00:00:00 2001 From: "ct-sdks[bot]" <153784748+ct-sdks[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:44:49 +0000 Subject: [PATCH] build(codegen): updating SDK --- changes.md | 16 +- ...sourceByProjectKeyChannelsKeyByKeyTest.php | 624 ++++++++++++++++++ .../ResourceByProjectKeyChannelsTest.php | 12 + lib/commercetools-api/docs/RequestBuilder.md | 61 ++ .../ByProjectKeyChannelsKeyByKeyDelete.php | 170 +++++ .../ByProjectKeyChannelsKeyByKeyGet.php | 155 +++++ .../ByProjectKeyChannelsKeyByKeyHead.php | 139 ++++ .../ByProjectKeyChannelsKeyByKeyPost.php | 160 +++++ .../Resource/ResourceByProjectKeyChannels.php | 11 + .../ResourceByProjectKeyChannelsKeyByKey.php | 69 ++ references.txt | 1 + 11 files changed, 1415 insertions(+), 3 deletions(-) create mode 100644 lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsKeyByKeyTest.php create mode 100644 lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyDelete.php create mode 100644 lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyGet.php create mode 100644 lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyHead.php create mode 100644 lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyPost.php create mode 100644 lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannelsKeyByKey.php diff --git a/changes.md b/changes.md index 53dc55e046b..117d08944c9 100644 --- a/changes.md +++ b/changes.md @@ -1,8 +1,18 @@ -**Import changes** +**Api changes**
-Removed Type(s) +Added Resource(s) -- :warning: removed type `ReferencedResourceNotFound` +- added resource `/{projectKey}/channels/key={key}` +
+ + +
+Added Method(s) + +- added method `$apiRoot->withProjectKey()->channels()->withKey()->get()` +- added method `$apiRoot->withProjectKey()->channels()->withKey()->head()` +- added method `$apiRoot->withProjectKey()->channels()->withKey()->post()` +- added method `$apiRoot->withProjectKey()->channels()->withKey()->delete()`
diff --git a/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsKeyByKeyTest.php b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsKeyByKeyTest.php new file mode 100644 index 00000000000..66f92a88520 --- /dev/null +++ b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsKeyByKeyTest.php @@ -0,0 +1,624 @@ +assertSame(strtolower($method), strtolower($request->getMethod())); + $this->assertSame($relativeUri, (string) $request->getUri()); + if (!is_null($body)) { + $this->assertJsonStringEqualsJsonString($body, (string) $request->getBody()); + } else { + $this->assertSame("", (string) $request->getBody()); + } + } + + + + /** + * @dataProvider getRequestBuilderResponses() + */ + public function testMapFromResponse(callable $builderFunction, $statusCode) + { + $builder = new ApiRequestBuilder(); + $request = $builderFunction($builder); + $this->assertInstanceOf(ApiRequest::class, $request); + + $response = new Response($statusCode, [], "{}"); + $this->assertInstanceOf(JsonObject::class, $request->mapFromResponse($response)); + } + + /** + * @dataProvider getRequestBuilders() + */ + public function testExecuteClientException(callable $builderFunction) + { + $client = $this->createMock(ClientInterface::class); + + $builder = new ApiRequestBuilder($client); + $request = $builderFunction($builder); + $client->method("send")->willThrowException(new ClientException("Oops!", $request, new Response(400))); + + $this->expectException(ApiClientException::class); + $request->execute(); + } + + /** + * @dataProvider getRequestBuilders() + */ + public function testExecuteServerException(callable $builderFunction) + { + $client = $this->createMock(ClientInterface::class); + + $builder = new ApiRequestBuilder($client); + $request = $builderFunction($builder); + $client->method("send")->willThrowException(new ServerException("Oops!", $request, new Response(500))); + + $this->expectException(ApiServerException::class); + $request->execute(); + } + + public function getRequests() + { + return [ + 'ByProjectKeyChannelsKeyByKeyGet_withExpand' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey('test_projectKey') + ->channels() + ->withKey('test_key') + ->get() + ->withExpand('expand'); + }, + 'get', + 'test_projectKey/channels/key=test_key?expand=expand', + ], + 'ByProjectKeyChannelsKeyByKeyGet' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("test_projectKey") + ->channels() + ->withKey("test_key") + ->get(); + }, + 'get', + 'test_projectKey/channels/key=test_key', + ], + 'ByProjectKeyChannelsKeyByKeyHead' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("test_projectKey") + ->channels() + ->withKey("test_key") + ->head(); + }, + 'head', + 'test_projectKey/channels/key=test_key', + ], + 'ByProjectKeyChannelsKeyByKeyPost_withExpand' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey('test_projectKey') + ->channels() + ->withKey('test_key') + ->post(null) + ->withExpand('expand'); + }, + 'post', + 'test_projectKey/channels/key=test_key?expand=expand', + ], + 'ByProjectKeyChannelsKeyByKeyPost' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("test_projectKey") + ->channels() + ->withKey("test_key") + ->post(null); + }, + 'post', + 'test_projectKey/channels/key=test_key', + ], + 'ByProjectKeyChannelsKeyByKeyDelete_withVersion' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey('test_projectKey') + ->channels() + ->withKey('test_key') + ->delete() + ->withVersion('version'); + }, + 'delete', + 'test_projectKey/channels/key=test_key?version=version', + ], + 'ByProjectKeyChannelsKeyByKeyDelete_withExpand' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey('test_projectKey') + ->channels() + ->withKey('test_key') + ->delete() + ->withExpand('expand'); + }, + 'delete', + 'test_projectKey/channels/key=test_key?expand=expand', + ], + 'ByProjectKeyChannelsKeyByKeyDelete' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("test_projectKey") + ->channels() + ->withKey("test_key") + ->delete(); + }, + 'delete', + 'test_projectKey/channels/key=test_key', + ] + ]; + } + + public function getResources() + { + return [ + ]; + } + + public function getRequestBuilders() + { + return [ + 'ByProjectKeyChannelsKeyByKeyGet' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + } + ], + 'ByProjectKeyChannelsKeyByKeyHead' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + } + ], + 'ByProjectKeyChannelsKeyByKeyPost' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + } + ], + 'ByProjectKeyChannelsKeyByKeyDelete' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + } + ] + ]; + } + + public function getRequestBuilderResponses() + { + return [ + 'ByProjectKeyChannelsKeyByKeyGet_200' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 200 + ], + 'ByProjectKeyChannelsKeyByKeyGet_400' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 400 + ], + 'ByProjectKeyChannelsKeyByKeyGet_401' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 401 + ], + 'ByProjectKeyChannelsKeyByKeyGet_403' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 403 + ], + 'ByProjectKeyChannelsKeyByKeyGet_404' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 404 + ], + 'ByProjectKeyChannelsKeyByKeyGet_500' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 500 + ], + 'ByProjectKeyChannelsKeyByKeyGet_502' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 502 + ], + 'ByProjectKeyChannelsKeyByKeyGet_503' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 503 + ], + 'ByProjectKeyChannelsKeyByKeyGet_599' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); + }, + 599 + ], + 'ByProjectKeyChannelsKeyByKeyHead_200' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 200 + ], + 'ByProjectKeyChannelsKeyByKeyHead_404' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 404 + ], + 'ByProjectKeyChannelsKeyByKeyHead_400' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 400 + ], + 'ByProjectKeyChannelsKeyByKeyHead_401' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 401 + ], + 'ByProjectKeyChannelsKeyByKeyHead_403' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 403 + ], + 'ByProjectKeyChannelsKeyByKeyHead_500' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 500 + ], + 'ByProjectKeyChannelsKeyByKeyHead_502' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 502 + ], + 'ByProjectKeyChannelsKeyByKeyHead_503' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 503 + ], + 'ByProjectKeyChannelsKeyByKeyHead_599' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); + }, + 599 + ], + 'ByProjectKeyChannelsKeyByKeyPost_200' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 200 + ], + 'ByProjectKeyChannelsKeyByKeyPost_409' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 409 + ], + 'ByProjectKeyChannelsKeyByKeyPost_400' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 400 + ], + 'ByProjectKeyChannelsKeyByKeyPost_401' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 401 + ], + 'ByProjectKeyChannelsKeyByKeyPost_403' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 403 + ], + 'ByProjectKeyChannelsKeyByKeyPost_404' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 404 + ], + 'ByProjectKeyChannelsKeyByKeyPost_500' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 500 + ], + 'ByProjectKeyChannelsKeyByKeyPost_502' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 502 + ], + 'ByProjectKeyChannelsKeyByKeyPost_503' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 503 + ], + 'ByProjectKeyChannelsKeyByKeyPost_599' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); + }, + 599 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_200' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 200 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_409' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 409 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_400' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 400 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_401' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 401 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_403' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 403 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_404' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 404 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_500' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 500 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_502' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 502 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_503' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 503 + ], + 'ByProjectKeyChannelsKeyByKeyDelete_599' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); + }, + 599 + ] + ]; + } +} diff --git a/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsTest.php b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsTest.php index d0ed4f22223..d2299e19e4a 100644 --- a/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsTest.php +++ b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyChannelsTest.php @@ -10,6 +10,7 @@ use Commercetools\Api\Client\ApiRequestBuilder; use Commercetools\Api\Client\Resource\ResourceByProjectKeyChannelsByID; +use Commercetools\Api\Client\Resource\ResourceByProjectKeyChannelsKeyByKey; use Commercetools\Base\JsonObject; use Commercetools\Client\ApiRequest; use Commercetools\Exception\ApiClientException; @@ -247,6 +248,17 @@ function (ApiRequestBuilder $builder): ResourceByProjectKeyChannelsByID { ResourceByProjectKeyChannelsByID::class, ['projectKey' => 'test_projectKey', 'ID' => 'test_ID'], '/{projectKey}/channels/{ID}' + ], + 'ResourceByProjectKeyChannelsKeyByKey' => [ + function (ApiRequestBuilder $builder): ResourceByProjectKeyChannelsKeyByKey { + return $builder + ->withProjectKey("test_projectKey") + ->channels() + ->withKey("test_key"); + }, + ResourceByProjectKeyChannelsKeyByKey::class, + ['projectKey' => 'test_projectKey', 'key' => 'test_key'], + '/{projectKey}/channels/key={key}' ] ]; } diff --git a/lib/commercetools-api/docs/RequestBuilder.md b/lib/commercetools-api/docs/RequestBuilder.md index a66c4a878b7..4367e1577f9 100644 --- a/lib/commercetools-api/docs/RequestBuilder.md +++ b/lib/commercetools-api/docs/RequestBuilder.md @@ -2346,6 +2346,67 @@ $request = $builder ->withId("ID") ->delete(); ``` +## `withProjectKey("projectKey")->channels()->withKey("key")->get()` + +null + +### Example +```php +use Commercetools\Api\Client\ApiRequestBuilder; + +$builder = new ApiRequestBuilder(); +$request = $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->get(); +``` +## `withProjectKey("projectKey")->channels()->withKey("key")->head()` + +Checks if a Channel exists for a given `key`. Returns a `200 OK` status if the Channel exists or a `404 Not Found` otherwise. + +### Example +```php +use Commercetools\Api\Client\ApiRequestBuilder; + +$builder = new ApiRequestBuilder(); +$request = $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->head(); +``` +## `withProjectKey("projectKey")->channels()->withKey("key")->post(null)` + +null + +### Example +```php +use Commercetools\Api\Client\ApiRequestBuilder; + +$builder = new ApiRequestBuilder(); +$request = $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->post(null); +``` +## `withProjectKey("projectKey")->channels()->withKey("key")->delete()` + +Returns a [ReferenceExists](ctp:api:type:ReferenceExistsError) error if other resources reference the Channel to be deleted. + + +### Example +```php +use Commercetools\Api\Client\ApiRequestBuilder; + +$builder = new ApiRequestBuilder(); +$request = $builder + ->withProjectKey("projectKey") + ->channels() + ->withKey("key") + ->delete(); +``` ## `withProjectKey("projectKey")->customObjects()->get()` For performance reasons, it is highly advisable to query for Custom Objects in a container by using the `container` field in the `where` predicate. diff --git a/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyDelete.php b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyDelete.php new file mode 100644 index 00000000000..87b1c1b4a9d --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyDelete.php @@ -0,0 +1,170 @@ + + * @template-implements Conflicting + * @template-implements Expandable + * @template-implements Errorable + * @template-implements Deprecatable200 + */ +class ByProjectKeyChannelsKeyByKeyDelete extends ApiRequest implements Versioned, Conflicting, Expandable, Errorable, Deprecatable200 +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, string $key, $body = null, array $headers = [], ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}', '{key}'], [$projectKey, $key], '{projectKey}/channels/key={key}'); + parent::__construct($client, 'DELETE', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * @return Channel|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 '200': + $resultType = ChannelModel::class; + + break; + case '409': + $resultType = ErrorResponseModel::class; + + break; + 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 $resultType + * + * @return null|T|Channel|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 $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[] $version + */ + public function withVersion($version): ByProjectKeyChannelsKeyByKeyDelete + { + return $this->withQueryParam('version', $version); + } + + /** + * + * @psalm-param scalar|scalar[] $expand + */ + public function withExpand($expand): ByProjectKeyChannelsKeyByKeyDelete + { + return $this->withQueryParam('expand', $expand); + } +} diff --git a/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyGet.php b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyGet.php new file mode 100644 index 00000000000..c3a4f8b81f1 --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyGet.php @@ -0,0 +1,155 @@ + + * @template-implements Errorable + * @template-implements Deprecatable200 + */ +class ByProjectKeyChannelsKeyByKeyGet extends ApiRequest implements Expandable, Errorable, Deprecatable200 +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, string $key, $body = null, array $headers = [], ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}', '{key}'], [$projectKey, $key], '{projectKey}/channels/key={key}'); + parent::__construct($client, 'GET', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * @return Channel|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 '200': + $resultType = ChannelModel::class; + + break; + 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 $resultType + * + * @return null|T|Channel|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 $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[] $expand + */ + public function withExpand($expand): ByProjectKeyChannelsKeyByKeyGet + { + return $this->withQueryParam('expand', $expand); + } +} diff --git a/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyHead.php b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyHead.php new file mode 100644 index 00000000000..82640f180aa --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyHead.php @@ -0,0 +1,139 @@ + + * @template-implements Deprecatable200 + */ +class ByProjectKeyChannelsKeyByKeyHead extends ApiRequest implements Errorable, Deprecatable200 +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, string $key, $body = null, array $headers = [], ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}', '{key}'], [$projectKey, $key], '{projectKey}/channels/key={key}'); + parent::__construct($client, 'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $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 $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 $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; + } + ); + } +} diff --git a/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyPost.php b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyPost.php new file mode 100644 index 00000000000..3922a047ff7 --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ByProjectKeyChannelsKeyByKeyPost.php @@ -0,0 +1,160 @@ + + * @template-implements Expandable + * @template-implements Deprecatable200 + * @template-implements Errorable + */ +class ByProjectKeyChannelsKeyByKeyPost extends ApiRequest implements Conflicting, Expandable, Deprecatable200, Errorable +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, string $key, $body = null, array $headers = [], ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}', '{key}'], [$projectKey, $key], '{projectKey}/channels/key={key}'); + parent::__construct($client, 'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * @return Channel|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 '200': + $resultType = ChannelModel::class; + + break; + case '409': + $resultType = ErrorResponseModel::class; + + break; + 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 $resultType + * + * @return null|T|Channel|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 $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[] $expand + */ + public function withExpand($expand): ByProjectKeyChannelsKeyByKeyPost + { + return $this->withQueryParam('expand', $expand); + } +} diff --git a/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannels.php b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannels.php index 87a7b085e70..f3753482407 100644 --- a/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannels.php +++ b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannels.php @@ -37,6 +37,17 @@ public function withId(string $ID = null): ResourceByProjectKeyChannelsByID return new ResourceByProjectKeyChannelsByID($args, $this->getClient()); } + /** + */ + public function withKey(string $key = null): ResourceByProjectKeyChannelsKeyByKey + { + $args = $this->getArgs(); + if (!is_null($key)) { + $args['key'] = $key; + } + + return new ResourceByProjectKeyChannelsKeyByKey($args, $this->getClient()); + } /** * @psalm-param ?object|array|string $body diff --git a/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannelsKeyByKey.php b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannelsKeyByKey.php new file mode 100644 index 00000000000..adcfe5654fe --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyChannelsKeyByKey.php @@ -0,0 +1,69 @@ + $args + */ + public function __construct(array $args = [], ClientInterface $client = null) + { + parent::__construct('/{projectKey}/channels/key={key}', $args, $client); + } + + /** + * @psalm-param ?object|array|string $body + * @psalm-param array $headers + */ + public function get($body = null, array $headers = []): ByProjectKeyChannelsKeyByKeyGet + { + $args = $this->getArgs(); + + return new ByProjectKeyChannelsKeyByKeyGet($args['projectKey'], $args['key'], $body, $headers, $this->getClient()); + } + /** + * @psalm-param ?object|array|string $body + * @psalm-param array $headers + */ + public function head($body = null, array $headers = []): ByProjectKeyChannelsKeyByKeyHead + { + $args = $this->getArgs(); + + return new ByProjectKeyChannelsKeyByKeyHead($args['projectKey'], $args['key'], $body, $headers, $this->getClient()); + } + /** + * @psalm-param ?ChannelUpdate $body + * @psalm-param array $headers + */ + public function post(?ChannelUpdate $body = null, array $headers = []): ByProjectKeyChannelsKeyByKeyPost + { + $args = $this->getArgs(); + + return new ByProjectKeyChannelsKeyByKeyPost($args['projectKey'], $args['key'], $body, $headers, $this->getClient()); + } + /** + * @psalm-param ?object|array|string $body + * @psalm-param array $headers + */ + public function delete($body = null, array $headers = []): ByProjectKeyChannelsKeyByKeyDelete + { + $args = $this->getArgs(); + + return new ByProjectKeyChannelsKeyByKeyDelete($args['projectKey'], $args['key'], $body, $headers, $this->getClient()); + } +} diff --git a/references.txt b/references.txt index 24b8c86b760..6e159582a90 100644 --- a/references.txt +++ b/references.txt @@ -333,3 +333,4 @@ df53588d26d7953dfdf44166866ca03045f0a70b 6b69c5425fe16564147deb9b1d6a9a1078dc5330 99e7aa1c7e3ba67a59b6df3efbaf4e320611c549 269027575a6fd5a2a29387930064a06f22f09bbf +9c2f053d7f45e95984760f59a344e9630d90d843