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..df1ee93 --- /dev/null +++ b/src/ResourceGroup/Features.php @@ -0,0 +1,84 @@ +features = ['communication.chatbot_feature_1', 'communication.chatbot_feature_2'] + * + * try { + * $response = $client->features->check($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/FeaturesTest.php b/tests/src/ResourceGroup/FeaturesTest.php new file mode 100644 index 0000000..eb153fe --- /dev/null +++ b/tests/src/ResourceGroup/FeaturesTest.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); + } +}