Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way client inits, prepare for 5.0.0 release #46

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,30 @@ 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);
}

/**
* 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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

$this->mockResponse($payload, $mockResponse);

$response = $this->client->login();
$response = $this->client->login(12345, 'password');

expect($response)->toBeInstanceOf(LoginResponse::class);
});