From fd092f1983f26a7887828f0509bbdf2ffe5a9b44 Mon Sep 17 00:00:00 2001 From: Timirey Date: Wed, 17 Jul 2024 12:22:25 +0300 Subject: [PATCH] Change the way client inits, prepare for 5.0.0 release --- CHANGELOG.md | 10 +++++++--- README.md | 23 ++++++++++++++++++----- src/Client.php | 13 +++++++------ tests/Commands/LoginTest.php | 2 +- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e8dfd9..060d307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,22 @@ # Release Notes +## [5.0.0](https://github.com/timirey/xapi-php/compare/4.0.1..5.0.0) - 2024-07-17 + +* Changed the way client inits, `$userId` and `$password` are directly sent in the payload. + ## [4.0.1](https://github.com/timirey/xapi-php/compare/4.0.0..4.0.1) - 2024-07-16 -* Fix stream listener by adding feof() check. +* Fix stream listener by adding `feof()` check. ## [4.0.0](https://github.com/timirey/xapi-php/compare/3.0.0..4.0.0) - 2024-07-16 * Dropped minimum support to 8.1 PHP. -* Added buffer to make sure it reads all the way down to "\n\n" guaranteed response separator. +* Added buffer to make sure it reads all the way down to `"\n\n"` guaranteed response separator. ## [3.0.0](https://github.com/timirey/xapi-php/compare/2.0.1...3.0.0) - 2024-07-16 * Add minimum support of 8.3 PHP. -* Use json_validate() when parsing response. +* Use `json_validate()` when parsing response. ## [2.0.1](https://github.com/timirey/xapi-php/compare/2.0.0...2.0.1) - 2024-07-16 diff --git a/README.md b/README.md index af5363e..bcd2d93 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,17 @@ use Timirey\XApi\Responses\LogoutResponse; /** * @var Client */ -$client = new Client(userId: 123456789, password: 'password', host: Host::DEMO); +$client = new Client( + host: Host::DEMO +); /** * @var LoginResponse $loginResponse */ -$loginResponse = $client->login(); +$loginResponse = $client->login( + userId: 123456789, + password: 'password' +); /** * @var GetCalendarResponse $getCalendarResponse @@ -116,12 +121,17 @@ use Timirey\XApi\Client; /** * @var Client */ -$client = new Client(userId: 123456789, password: 'password', host: Host::DEMO); +$client = new Client( + host: Host::DEMO +); /** * @var LoginResponse $loginResponse */ -$loginResponse = $client->login(); +$loginResponse = $client->login( + userId: 123456789, + password: 'password' +); /** * @var string $streamSessionId @@ -166,7 +176,10 @@ use Timirey\XApi\Client; * @var LoginResponse $response * @var Client $client */ -$response = $client->login(); +$response = $client->login( + userId: 123456789, + password: 'password' +); ``` ### [logout](http://developers.xstore.pro/documentation/current#logout) diff --git a/src/Client.php b/src/Client.php index e460272..91d1094 100644 --- a/src/Client.php +++ b/src/Client.php @@ -81,13 +81,11 @@ class Client /** * Constructor for the Client class. * - * @param integer $userId User ID. - * @param string $password User password. - * @param Host $host Host URL. + * @param Host $host Host URL. * * @throws SocketException If socket is unable to init. */ - public function __construct(protected int $userId, protected string $password, protected Host $host) + public function __construct(protected Host $host) { $this->socket = new Socket($this->host->value); } @@ -95,15 +93,18 @@ public function __construct(protected int $userId, protected string $password, p /** * Logs in to the xStation5 API. * + * @param integer $userId User ID. + * @param string $password User password. + * * @return LoginResponse The response from the login request. * * @throws ErrorResponseException If the response indicates an error. * @throws JsonException If the response cannot be processed. * @throws InvalidResponseException Thrown when the API response is invalid or incomplete. */ - public function login(): LoginResponse + public function login(int $userId, string $password): LoginResponse { - return $this->request(new LoginPayload($this->userId, $this->password), LoginResponse::class); + return $this->request(new LoginPayload($userId, $password), LoginResponse::class); } /** diff --git a/tests/Commands/LoginTest.php b/tests/Commands/LoginTest.php index 27c5af4..e7b86aa 100644 --- a/tests/Commands/LoginTest.php +++ b/tests/Commands/LoginTest.php @@ -23,7 +23,7 @@ $this->mockResponse($payload, $mockResponse); - $response = $this->client->login(); + $response = $this->client->login(12345, 'password'); expect($response)->toBeInstanceOf(LoginResponse::class); });