mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-17 22:50:48 +00:00
parent
7162438837
commit
0650795d60
9 changed files with 265 additions and 33 deletions
|
@ -8,41 +8,20 @@ use Opdavies\Glassboxx\Config;
|
|||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
final class AuthTokenRequest extends AbstractRequest
|
||||
final class AuthTokenRequest extends AbstractRequest implements AuthTokenRequestInterface
|
||||
{
|
||||
public const ENDPOINT = '/integration/admin/token';
|
||||
|
||||
/** @var Config */
|
||||
private $config;
|
||||
|
||||
/** @var HttpClient */
|
||||
private $client;
|
||||
|
||||
public function __construct(HttpClientInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function withConfig(Config $config): self
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getToken(): string
|
||||
{
|
||||
$response = $this->client
|
||||
->request(
|
||||
'POST',
|
||||
self::BASE_URL.self::ENDPOINT,
|
||||
[
|
||||
'query' => [
|
||||
'password' => $this->config->getPassword(),
|
||||
'username' => $this->config->getUsername(),
|
||||
],
|
||||
]
|
||||
);
|
||||
$response = $this->client->request(
|
||||
'POST',
|
||||
self::BASE_URL.self::ENDPOINT,
|
||||
[
|
||||
'query' => [
|
||||
'password' => $this->config->getPassword(),
|
||||
'username' => $this->config->getUsername(),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
return json_decode($response->getContent());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue