From 5223d0e9f6608166fe61bdd585f857e4a6710ca2 Mon Sep 17 00:00:00 2001 From: Alex Komarichev Date: Fri, 15 Dec 2023 15:08:35 +0300 Subject: [PATCH 1/3] Add feature/check method --- src/Client.php | 12 +++ src/Model/Entity/Settings/Feature.php | 37 ++++++++ .../Request/Api/FeaturesCheckRequest.php | 30 +++++++ .../Response/Api/FeaturesCheckResponse.php | 31 +++++++ src/ResourceGroup/Features.php | 84 +++++++++++++++++++ tests/src/ResourceGroup/FeatureTest.php | 56 +++++++++++++ 6 files changed, 250 insertions(+) create mode 100644 src/Model/Entity/Settings/Feature.php create mode 100644 src/Model/Request/Api/FeaturesCheckRequest.php create mode 100644 src/Model/Response/Api/FeaturesCheckResponse.php create mode 100644 src/ResourceGroup/Features.php create mode 100644 tests/src/ResourceGroup/FeatureTest.php diff --git a/src/Client.php b/src/Client.php index e80617f..58e5ff3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -23,6 +23,7 @@ use RetailCrm\Api\ResourceGroup\CustomersCorporate; use RetailCrm\Api\ResourceGroup\CustomFields; use RetailCrm\Api\ResourceGroup\CustomMethods; use RetailCrm\Api\ResourceGroup\Delivery; +use RetailCrm\Api\ResourceGroup\Features; use RetailCrm\Api\ResourceGroup\Files; use RetailCrm\Api\ResourceGroup\Integration; use RetailCrm\Api\ResourceGroup\Inventories; @@ -75,6 +76,9 @@ class Client /** @var \RetailCrm\Api\ResourceGroup\Delivery */ public $delivery; + /** @var \RetailCrm\Api\ResourceGroup\Features */ + public $features; + /** @var \RetailCrm\Api\ResourceGroup\Files */ public $files; @@ -207,6 +211,14 @@ class Client $eventDispatcher, $logger ); + $this->features = new Features( + $url, + $httpClient, + $requestTransformer, + $responseTransformer, + $eventDispatcher, + $logger + ); $this->files = new Files( $url, $httpClient, diff --git a/src/Model/Entity/Settings/Feature.php b/src/Model/Entity/Settings/Feature.php new file mode 100644 index 0000000..d9568c0 --- /dev/null +++ b/src/Model/Entity/Settings/Feature.php @@ -0,0 +1,37 @@ +") + * @JMS\SerializedName("features") + */ + public $features; +} diff --git a/src/Model/Response/Api/FeaturesCheckResponse.php b/src/Model/Response/Api/FeaturesCheckResponse.php new file mode 100644 index 0000000..513e157 --- /dev/null +++ b/src/Model/Response/Api/FeaturesCheckResponse.php @@ -0,0 +1,31 @@ +") + * @JMS\SerializedName("features") + */ + public $features; +} diff --git a/src/ResourceGroup/Features.php b/src/ResourceGroup/Features.php new file mode 100644 index 0000000..e9db36d --- /dev/null +++ b/src/ResourceGroup/Features.php @@ -0,0 +1,84 @@ +features = ['communication.chatbot_feature_1', 'communication.chatbot_feature_2'] + * + * try { + * $response = $client->api->featuresCheck($request); + * } catch (ApiExceptionInterface $exception) { + * echo sprintf( + * 'Error from RetailCRM API (status code: %d): %s', + * $exception->getStatusCode(), + * $exception->getMessage + * ); + * + * if (count($exception->getErrorResponse()->errors) > 0) { + * echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors); + * } + * + * return; + * } + * + * echo 'System features ' . print_r($response->features, true); + * ``` + * + * @param \RetailCrm\Api\Model\Request\Api\FeaturesCheckRequest|null $request + * + * @return \RetailCrm\Api\Model\Response\Api\FeaturesCheckResponse + * @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface + * @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface + * @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException + * @throws \RetailCrm\Api\Exception\Api\ApiErrorException + * @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException + * @throws \RetailCrm\Api\Exception\Api\MissingParameterException + * @throws \RetailCrm\Api\Exception\Api\ValidationException + * @throws \RetailCrm\Api\Exception\Client\HandlerException + * @throws \RetailCrm\Api\Exception\Client\HttpClientException + */ + public function check(?FeaturesCheckRequest $request = null): FeaturesCheckResponse + { + /** @var FeaturesCheckResponse $response */ + $response = $this->sendRequest( + RequestMethod::GET, + 'features/check', + $request, + FeaturesCheckResponse::class + ); + + return $response; + } +} diff --git a/tests/src/ResourceGroup/FeatureTest.php b/tests/src/ResourceGroup/FeatureTest.php new file mode 100644 index 0000000..134dcb6 --- /dev/null +++ b/tests/src/ResourceGroup/FeatureTest.php @@ -0,0 +1,56 @@ +features = ['communication.chatbot_feature_1', 'communication.chatbot_feature_2']; + + $mock = static::createApiMockBuilder('features/check'); + $mock->matchMethod(RequestMethod::GET) + ->matchBody(static::encodeForm($request)) + ->reply(200) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $featuresCheck = $client->features->check($request); + + self::assertModelEqualsToResponse($json, $featuresCheck); + } +} From a682ce606a0604b10a2510361122667298f4dcb1 Mon Sep 17 00:00:00 2001 From: Alex Komarichev Date: Tue, 19 Dec 2023 15:55:23 +0300 Subject: [PATCH 2/3] Some refactor --- .../ResourceGroup/{FeatureTest.php => FeaturesTest.php} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename tests/src/ResourceGroup/{FeatureTest.php => FeaturesTest.php} (90%) diff --git a/tests/src/ResourceGroup/FeatureTest.php b/tests/src/ResourceGroup/FeaturesTest.php similarity index 90% rename from tests/src/ResourceGroup/FeatureTest.php rename to tests/src/ResourceGroup/FeaturesTest.php index 134dcb6..eb153fe 100644 --- a/tests/src/ResourceGroup/FeatureTest.php +++ b/tests/src/ResourceGroup/FeaturesTest.php @@ -3,7 +3,7 @@ /** * PHP version 7.3 * - * @category FeatureTest + * @category FeaturesTest * @package RetailCrm\Tests\ResourceGroup */ @@ -15,12 +15,12 @@ use RetailCrm\TestUtils\Factory\TestClientFactory; use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase; /** - * Class FeatureTest + * Class FeaturesTest * - * @category FeatureTest + * @category FeaturesTest * @package RetailCrm\Tests\ResourceGroup */ -class FeatureTest extends AbstractApiResourceGroupTestCase +class FeaturesTest extends AbstractApiResourceGroupTestCase { public function testCheck(): void { From a7bb610a0aa321ae7e73e90587c2c97ee37d0f5d Mon Sep 17 00:00:00 2001 From: Alex Komarichev Date: Wed, 20 Dec 2023 15:48:45 +0300 Subject: [PATCH 3/3] Fix example --- src/ResourceGroup/Features.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceGroup/Features.php b/src/ResourceGroup/Features.php index e9db36d..df1ee93 100644 --- a/src/ResourceGroup/Features.php +++ b/src/ResourceGroup/Features.php @@ -38,7 +38,7 @@ class Features extends AbstractApiResourceGroup * $request->features = ['communication.chatbot_feature_1', 'communication.chatbot_feature_2'] * * try { - * $response = $client->api->featuresCheck($request); + * $response = $client->features->check($request); * } catch (ApiExceptionInterface $exception) { * echo sprintf( * 'Error from RetailCRM API (status code: %d): %s',