Add feature check method
This commit is contained in:
commit
3054974756
@ -23,6 +23,7 @@ use RetailCrm\Api\ResourceGroup\CustomersCorporate;
|
|||||||
use RetailCrm\Api\ResourceGroup\CustomFields;
|
use RetailCrm\Api\ResourceGroup\CustomFields;
|
||||||
use RetailCrm\Api\ResourceGroup\CustomMethods;
|
use RetailCrm\Api\ResourceGroup\CustomMethods;
|
||||||
use RetailCrm\Api\ResourceGroup\Delivery;
|
use RetailCrm\Api\ResourceGroup\Delivery;
|
||||||
|
use RetailCrm\Api\ResourceGroup\Features;
|
||||||
use RetailCrm\Api\ResourceGroup\Files;
|
use RetailCrm\Api\ResourceGroup\Files;
|
||||||
use RetailCrm\Api\ResourceGroup\Integration;
|
use RetailCrm\Api\ResourceGroup\Integration;
|
||||||
use RetailCrm\Api\ResourceGroup\Inventories;
|
use RetailCrm\Api\ResourceGroup\Inventories;
|
||||||
@ -75,6 +76,9 @@ class Client
|
|||||||
/** @var \RetailCrm\Api\ResourceGroup\Delivery */
|
/** @var \RetailCrm\Api\ResourceGroup\Delivery */
|
||||||
public $delivery;
|
public $delivery;
|
||||||
|
|
||||||
|
/** @var \RetailCrm\Api\ResourceGroup\Features */
|
||||||
|
public $features;
|
||||||
|
|
||||||
/** @var \RetailCrm\Api\ResourceGroup\Files */
|
/** @var \RetailCrm\Api\ResourceGroup\Files */
|
||||||
public $files;
|
public $files;
|
||||||
|
|
||||||
@ -207,6 +211,14 @@ class Client
|
|||||||
$eventDispatcher,
|
$eventDispatcher,
|
||||||
$logger
|
$logger
|
||||||
);
|
);
|
||||||
|
$this->features = new Features(
|
||||||
|
$url,
|
||||||
|
$httpClient,
|
||||||
|
$requestTransformer,
|
||||||
|
$responseTransformer,
|
||||||
|
$eventDispatcher,
|
||||||
|
$logger
|
||||||
|
);
|
||||||
$this->files = new Files(
|
$this->files = new Files(
|
||||||
$url,
|
$url,
|
||||||
$httpClient,
|
$httpClient,
|
||||||
|
37
src/Model/Entity/Settings/Feature.php
Normal file
37
src/Model/Entity/Settings/Feature.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category Feature
|
||||||
|
* @package RetailCrm\Api\Model\Entity\Settings
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Entity\Settings;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Feature
|
||||||
|
*
|
||||||
|
* @category Feature
|
||||||
|
* @package RetailCrm\Api\Model\Entity\Settings
|
||||||
|
*/
|
||||||
|
class Feature
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @JMS\Type("string")
|
||||||
|
* @JMS\SerializedName("code")
|
||||||
|
*/
|
||||||
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @JMS\Type("bool")
|
||||||
|
* @JMS\SerializedName("available")
|
||||||
|
*/
|
||||||
|
public $available;
|
||||||
|
}
|
30
src/Model/Request/Api/FeaturesCheckRequest.php
Normal file
30
src/Model/Request/Api/FeaturesCheckRequest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category FeaturesCheckRequest
|
||||||
|
* @package RetailCrm\Api\Model\Request\Api
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Request\Api;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
use RetailCrm\Api\Interfaces\RequestInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FeaturesCheckRequest
|
||||||
|
*
|
||||||
|
* @category FeaturesCheckRequest
|
||||||
|
* @package RetailCrm\Api\Model\Request\Api
|
||||||
|
*/
|
||||||
|
class FeaturesCheckRequest implements RequestInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string[]
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<string>")
|
||||||
|
* @JMS\SerializedName("features")
|
||||||
|
*/
|
||||||
|
public $features;
|
||||||
|
}
|
31
src/Model/Response/Api/FeaturesCheckResponse.php
Normal file
31
src/Model/Response/Api/FeaturesCheckResponse.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category FeaturesCheckResponse
|
||||||
|
* @package RetailCrm\Api\Model\Response\Api
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\Model\Response\Api;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||||
|
use RetailCrm\Api\Model\Entity\Settings\Feature;
|
||||||
|
use RetailCrm\Api\Model\Response\SuccessResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FeaturesCheckResponse
|
||||||
|
*
|
||||||
|
* @category FeaturesCheckResponse
|
||||||
|
* @package RetailCrm\Api\Model\Response\Api
|
||||||
|
*/
|
||||||
|
class FeaturesCheckResponse extends SuccessResponse
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \RetailCrm\Api\Model\Entity\Settings\Feature[]
|
||||||
|
*
|
||||||
|
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Settings\Feature>")
|
||||||
|
* @JMS\SerializedName("features")
|
||||||
|
*/
|
||||||
|
public $features;
|
||||||
|
}
|
84
src/ResourceGroup/Features.php
Normal file
84
src/ResourceGroup/Features.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category Features
|
||||||
|
* @package RetailCrm\Api\ResourceGroup
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Api\ResourceGroup;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Enum\RequestMethod;
|
||||||
|
use RetailCrm\Api\Model\Request\Api\FeaturesCheckRequest;
|
||||||
|
use RetailCrm\Api\Model\Response\Api\FeaturesCheckResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Features
|
||||||
|
*
|
||||||
|
* @category Features
|
||||||
|
* @package RetailCrm\Api\ResourceGroup
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
|
*/
|
||||||
|
class Features extends AbstractApiResourceGroup
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Makes GET "/api/v5/features/check" request.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* ```php
|
||||||
|
* use RetailCrm\Api\Factory\SimpleClientFactory;
|
||||||
|
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
|
||||||
|
* use RetailCrm\Api\Model\Request\Api\FeaturesCheckRequest;
|
||||||
|
*
|
||||||
|
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
|
||||||
|
*
|
||||||
|
* $request = new FeaturesCheckRequest()
|
||||||
|
* $request->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;
|
||||||
|
}
|
||||||
|
}
|
56
tests/src/ResourceGroup/FeaturesTest.php
Normal file
56
tests/src/ResourceGroup/FeaturesTest.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 7.3
|
||||||
|
*
|
||||||
|
* @category FeaturesTest
|
||||||
|
* @package RetailCrm\Tests\ResourceGroup
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests\ResourceGroup;
|
||||||
|
|
||||||
|
use RetailCrm\Api\Enum\RequestMethod;
|
||||||
|
use RetailCrm\Api\Model\Request\Api\FeaturesCheckRequest;
|
||||||
|
use RetailCrm\TestUtils\Factory\TestClientFactory;
|
||||||
|
use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FeaturesTest
|
||||||
|
*
|
||||||
|
* @category FeaturesTest
|
||||||
|
* @package RetailCrm\Tests\ResourceGroup
|
||||||
|
*/
|
||||||
|
class FeaturesTest extends AbstractApiResourceGroupTestCase
|
||||||
|
{
|
||||||
|
public function testCheck(): void
|
||||||
|
{
|
||||||
|
$json = <<<'EOF'
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"code": "communication.chatbot_feature_1",
|
||||||
|
"available": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "communication.chatbot_feature_2",
|
||||||
|
"available": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF;
|
||||||
|
$request = new FeaturesCheckRequest();
|
||||||
|
$request->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user