From d0f044c7bd9740ef00191e1b4c9ddc73f3af25fa Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 29 Sep 2025 19:25:28 +0300 Subject: [PATCH] Change api domain and authorization with header --- src/Api.php | 4 ++-- src/Client.php | 4 ++-- tests/ClientTest.php | 23 ++++++++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Api.php b/src/Api.php index f9c763c..87e16a3 100644 --- a/src/Api.php +++ b/src/Api.php @@ -48,11 +48,11 @@ use RuntimeException; */ class Api { - public const string LIBRARY_VERSION = '1.2.1'; + public const string LIBRARY_VERSION = '1.3.0'; public const string API_VERSION = '0.0.6'; - private const string API_BASE_URL = 'https://botapi.max.ru'; + private const string API_BASE_URL = 'https://platform-api.max.ru'; private const string METHOD_GET = 'GET'; private const string METHOD_POST = 'POST'; diff --git a/src/Client.php b/src/Client.php index 5d48fa7..742cbb9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -60,7 +60,6 @@ final readonly class Client implements ClientApiInterface */ public function request(string $method, string $uri, array $queryParams = [], array $body = []): array { - $queryParams['access_token'] = $this->accessToken; if (!empty($this->apiVersion)) { $queryParams['v'] = $this->apiVersion; } @@ -83,7 +82,8 @@ final readonly class Client implements ClientApiInterface $stream = $this->streamFactory->createStream($payload); $request = $request ->withBody($stream) - ->withHeader('Content-Type', 'application/json; charset=utf-8'); + ->withHeader('Content-Type', 'application/json; charset=utf-8') + ->withHeader('Authorization', $this->accessToken); } try { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 323179b..d2a85d1 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -35,7 +35,7 @@ final class ClientTest extends TestCase { private const string FAKE_TOKEN = '12345:abcdef'; private const string API_VERSION = '0.0.6'; - private const string API_BASE_URL = 'https://botapi.max.ru'; + private const string API_BASE_URL = 'https://platform-api.max.ru'; private MockObject&ClientInterface $httpClientMock; private MockObject&RequestFactoryInterface $requestFactoryMock; @@ -96,7 +96,6 @@ final class ClientTest extends TestCase { $uri = '/me'; $expectedUrl = self::API_BASE_URL . $uri . '?' . http_build_query([ - 'access_token' => self::FAKE_TOKEN, 'v' => self::API_VERSION, ]); $responsePayload = ['id' => 987, 'name' => 'TestBot']; @@ -138,8 +137,7 @@ final class ClientTest extends TestCase ]; $responsePayload = ['success' => true]; $expectedUrl = self::API_BASE_URL . $uri . '?' . http_build_query([ - 'access_token' => self::FAKE_TOKEN, - 'v' => self::API_VERSION + 'v' => self::API_VERSION, ]); $this->requestFactoryMock @@ -157,12 +155,23 @@ final class ClientTest extends TestCase })) ->willReturn($this->requestMock); + $headerCallCount = 0; $this->requestMock - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('withHeader') - ->with('Content-Type', 'application/json; charset=utf-8') - ->willReturn($this->requestMock); + ->willReturnCallback(function (string $header, string $value) use (&$headerCallCount) { + if ($headerCallCount === 0) { + $this->assertSame('Content-Type', $header); + $this->assertSame('application/json; charset=utf-8', $value); + } elseif ($headerCallCount === 1) { + $this->assertSame('Authorization', $header); + $this->assertSame(self::FAKE_TOKEN, $value); + } + $headerCallCount++; + + return $this->requestMock; + }); $this->responseMock->method('getStatusCode')->willReturn(200); $this->streamMock->method('__toString')->willReturn(json_encode($responsePayload));