Skip to content

Commit

Permalink
Merge pull request #47 from timirey/release/5.0.0
Browse files Browse the repository at this point in the history
Release/5.0.0
  • Loading branch information
timirey authored Jul 17, 2024
2 parents b1ad6f9 + 110b6f6 commit 738fcea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
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);
});

0 comments on commit 738fcea

Please sign in to comment.