88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Service\UDS;
|
|
|
|
use AllowDynamicProperties;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
#[AllowDynamicProperties]
|
|
class UDSClient
|
|
{
|
|
public function __construct(
|
|
private HttpClientInterface $httpClient,
|
|
EntityManagerInterface $entityManager,
|
|
private string $udsAPIurl,
|
|
private string $udsAuthLogin,
|
|
private string $udsAuthUsername,
|
|
private string $udsAuthPassword,
|
|
string $token,
|
|
string $scrambler
|
|
)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
*/
|
|
public function __invoke(): void
|
|
{
|
|
$this->login();
|
|
}
|
|
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
*/
|
|
public function login(): void
|
|
{
|
|
$response = $this->httpClient->request('POST', $this->udsAPIurl . '/auth/login', [
|
|
'json' => [
|
|
'login' => $this->udsAuthLogin,
|
|
'username' => $this->udsAuthUsername,
|
|
'password' => $this->udsAuthPassword
|
|
]
|
|
]);
|
|
|
|
$data = json_decode($response->getContent(), true);
|
|
$this->token = $data['token'];
|
|
$this->scrambler = $data['scrambler'];
|
|
}
|
|
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
*/
|
|
public function getServicePools(): array
|
|
{
|
|
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/servicespools/overview', [
|
|
'headers' => [
|
|
'X-Auth-Token' => $this->token,
|
|
'Content-Type' => 'application/json',
|
|
'Scrambler' => $this->scrambler
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function getServicePool(string $providerId, string $serviceId): array
|
|
{
|
|
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/providers/' . $providerId .'/services/'. $serviceId, [
|
|
'headers' => [
|
|
'X-Auth-Token' => $this->token,
|
|
'Content-Type' => 'application/json',
|
|
'Scrambler' => $this->scrambler
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function setServicePool(string $serviceId, array $payload): void
|
|
{
|
|
$response = $this->httpClient->request('PUT', $this->udsAPIurl . '/servicespools/' . $serviceId, [
|
|
'headers' => [
|
|
'X-Auth-Token' => $this->token,
|
|
'Content-Type' => 'application/json',
|
|
'Scrambler' => $this->scrambler
|
|
],
|
|
'json' => $payload
|
|
]);
|
|
}
|
|
} |