From d71a74edcc78086e0210479588ba73c606319853 Mon Sep 17 00:00:00 2001 From: Andrey Muriy Date: Wed, 16 Mar 2022 16:39:49 +0300 Subject: [PATCH] Add system-info method to api group --- src/Model/Response/Api/SystemInfoResponse.php | 46 ++++++++++++++++ src/ResourceGroup/Api.php | 53 +++++++++++++++++++ tests/src/ResourceGroup/ApiTest.php | 21 ++++++++ 3 files changed, 120 insertions(+) create mode 100644 src/Model/Response/Api/SystemInfoResponse.php diff --git a/src/Model/Response/Api/SystemInfoResponse.php b/src/Model/Response/Api/SystemInfoResponse.php new file mode 100644 index 0000000..47916bc --- /dev/null +++ b/src/Model/Response/Api/SystemInfoResponse.php @@ -0,0 +1,46 @@ +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; + } } diff --git a/tests/src/ResourceGroup/ApiTest.php b/tests/src/ResourceGroup/ApiTest.php index 08247e4..8ec6a0e 100644 --- a/tests/src/ResourceGroup/ApiTest.php +++ b/tests/src/ResourceGroup/ApiTest.php @@ -77,4 +77,25 @@ EOF; ], $credentials->credentials); 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); + } }