1
0
mirror of synced 2024-11-22 05:16:07 +03:00

Add system-info method to api group

This commit is contained in:
Andrey Muriy 2022-03-16 16:39:49 +03:00
parent 123a59fdf8
commit d71a74edcc
3 changed files with 120 additions and 0 deletions

View File

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

View File

@ -18,6 +18,7 @@ use RetailCrm\Api\Interfaces\RequestTransformerInterface;
use RetailCrm\Api\Interfaces\ResponseTransformerInterface; use RetailCrm\Api\Interfaces\ResponseTransformerInterface;
use RetailCrm\Api\Model\Response\Api\ApiVersionsResponse; use RetailCrm\Api\Model\Response\Api\ApiVersionsResponse;
use RetailCrm\Api\Model\Response\Api\Credentials; use RetailCrm\Api\Model\Response\Api\Credentials;
use RetailCrm\Api\Model\Response\Api\SystemInfoResponse;
/** /**
* Class Api * Class Api
@ -160,4 +161,56 @@ class Api extends AbstractApiResourceGroup
); );
return $response; return $response;
} }
/**
* Makes GET "/api/system-info" request.
*
* Example:
* ```php
* use RetailCrm\Api\Factory\SimpleClientFactory;
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
*
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
*
* try {
* $systemInfo = $client->api->systemInfo();
* } 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 'Technical URL: ' . $systemInfo->technicalUrl;
* ```
*
* @return \RetailCrm\Api\Model\Response\Api\SystemInfoResponse
* @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 systemInfo(): SystemInfoResponse
{
/** @var SystemInfoResponse $response */
$response = $this->sendRequest(
RequestMethod::GET,
'system-info',
null,
SystemInfoResponse::class
);
return $response;
}
} }

View File

@ -77,4 +77,25 @@ EOF;
], $credentials->credentials); ], $credentials->credentials);
self::assertEquals(["order_read", "customer_read", "reference_read"], $credentials->scopes); self::assertEquals(["order_read", "customer_read", "reference_read"], $credentials->scopes);
} }
public function testSystemInfo(): void
{
$json = <<<'EOF'
{
"success": true,
"systemVersion": "8.1.51",
"publicUrl": "https://test.retailcrm.ru",
"technicalUrl": "https://testwtestxtestvtestytestwtesthm6.retailcrm.io"
}
EOF;
$mock = static::createUnversionedApiMockBuilder('system-info');
$mock->matchMethod(RequestMethod::GET)
->reply(200)
->withBody($json);
$client = TestClientFactory::createClient($mock->getClient());
$systemInfo = $client->api->systemInfo();
self::assertModelEqualsToResponse($json, $systemInfo);
}
} }