1
0
mirror of synced 2024-11-21 21:06:07 +03:00

Add update-scopes method to integration group (#142)

Co-authored-by: Andrey Muriy <andrey.muriy@gmail.com>
This commit is contained in:
Andrey 2022-04-01 17:26:14 +03:00 committed by GitHub
parent 0b6cbb6794
commit 13caebdbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 191 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
/**
* PHP version 7.3
*
* @category Requires
* @package RetailCrm\Api\Model\Entity\Integration
*/
namespace RetailCrm\Api\Model\Entity\Integration;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
/**
* Class Requires
*
* @category Requires
* @package RetailCrm\Api\Model\Entity\Integration
*/
class Requires
{
/**
* @var string[]
*
* @JMS\Type("array")
* @JMS\SerializedName("scopes")
*/
public $scopes;
}

View File

@ -0,0 +1,34 @@
<?php
/**
* PHP version 7.3
*
* @category IntegrationModulesEditRequest
* @package RetailCrm\Api\Model\Request\Integration
*/
namespace RetailCrm\Api\Model\Request\Integration;
use RetailCrm\Api\Component\FormData\Mapping as Form;
use RetailCrm\Api\Interfaces\RequestInterface;
use RetailCrm\Api\Model\Entity\Integration\Requires;
class IntegrationModuleUpdateScopesRequest implements RequestInterface
{
/**
* @var \RetailCrm\Api\Model\Entity\Integration\Requires
*
* @Form\Type("RetailCrm\Api\Model\Entity\Integration\Requires")
* @Form\SerializedName("requires")
* @Form\JsonField()
*/
public $requires;
/**
* IntegrationModuleUpdateScopesRequest constructor.
*/
public function __construct(Requires $requires)
{
$this->requires = $requires;
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* PHP version 7.3
*
* @category IntegrationModuleUpdateScopesResponse
* @package RetailCrm\Api\Model\Response\Integration
*/
namespace RetailCrm\Api\Model\Response\Integration;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
use RetailCrm\Api\Model\Response\SuccessResponse;
/**
* Class IntegrationModuleUpdateScopesResponse
*
* @category IntegrationModuleUpdateScopesResponse
* @package RetailCrm\Api\Model\Response\Integration
*/
class IntegrationModuleUpdateScopesResponse extends SuccessResponse
{
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("apiKey")
*/
public $apiKey;
}

View File

@ -11,8 +11,10 @@ namespace RetailCrm\Api\ResourceGroup;
use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Model\Request\Integration\IntegrationModulesEditRequest;
use RetailCrm\Api\Model\Request\Integration\IntegrationModuleUpdateScopesRequest;
use RetailCrm\Api\Model\Response\Integration\IntegrationModulesEditResponse;
use RetailCrm\Api\Model\Response\Integration\IntegrationModulesGetResponse;
use RetailCrm\Api\Model\Response\Integration\IntegrationModuleUpdateScopesResponse;
/**
* Class Integration
@ -148,4 +150,71 @@ class Integration extends AbstractApiResourceGroup
);
return $response;
}
/**
* Makes POST "/api/v5/integration-modules/{code}/update-scopes" request.
*
* Example:
* ```php
* use RetailCrm\Api\Factory\SimpleClientFactory;
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
* use RetailCrm\Api\Model\Entity\Integration\IntegrationModule;
* use RetailCrm\Api\Model\Entity\Integration\Integrations;
* use RetailCrm\Api\Model\Entity\Integration\Transport\TransportConfiguration;
* use RetailCrm\Api\Model\Request\Integration\IntegrationModulesEditRequest;
*
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
*
* $requires = [
* 'integration_read',
* 'integration_write',
* ];
* $request = new IntegrationModuleUpdateScopesRequest($requires);
*
* try {
* $response = $client->integration->edit('test-integration', $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 'Info: ' . print_r($response->info, true);
* ```
*
* @param string $code
* @param \RetailCrm\Api\Model\Request\Integration\IntegrationModuleUpdateScopesRequest $request
*
* @return \RetailCrm\Api\Model\Response\Integration\IntegrationModuleUpdateScopesResponse
* @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 updateScopes(
string $code,
IntegrationModuleUpdateScopesRequest $request
): IntegrationModuleUpdateScopesResponse {
/** @var IntegrationModuleUpdateScopesResponse $response */
$response = $this->sendRequest(
RequestMethod::POST,
'integration-modules/' . $code . '/update-scopes',
$request,
IntegrationModuleUpdateScopesResponse::class
);
return $response;
}
}

View File

@ -19,8 +19,10 @@ use RetailCrm\Api\Model\Entity\Integration\Integrations;
use RetailCrm\Api\Model\Entity\Integration\Payment\Actions;
use RetailCrm\Api\Model\Entity\Integration\Payment\PaymentConfiguration;
use RetailCrm\Api\Model\Entity\Integration\Payment\Shop;
use RetailCrm\Api\Model\Entity\Integration\Requires;
use RetailCrm\Api\Model\Entity\Integration\Transport\TransportConfiguration;
use RetailCrm\Api\Model\Request\Integration\IntegrationModulesEditRequest;
use RetailCrm\Api\Model\Request\Integration\IntegrationModuleUpdateScopesRequest;
use RetailCrm\TestUtils\Factory\TestClientFactory;
use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase;
@ -293,4 +295,31 @@ EOF;
return $statusList;
}
public function testUpdateScopes(): void
{
$json = <<<'EOF'
{
"success": true,
"apiKey": "SOMEAPIKEY"
}
EOF;
$requires = new Requires();
$requires->scopes = [
'integration_read',
'integration_write',
];
$request = new IntegrationModuleUpdateScopesRequest($requires);
$mock = static::createApiMockBuilder('integration-modules/test-integration/update-scopes');
$mock->matchMethod(RequestMethod::POST)
->matchBody(static::encodeForm($request))
->reply(200)
->withBody($json);
$client = TestClientFactory::createClient($mock->getClient());
$response = $client->integration->updateScopes('test-integration', $request);
self::assertModelEqualsToResponse($json, $response);
}
}