-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.php
38 lines (31 loc) · 1.03 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Millon\PhpRefactoring\Service\ExchangeRates\Client;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\GuzzleException;
use Millon\PhpRefactoring\Entity\Collection\Rates;
use Millon\PhpRefactoring\Service\Contracts\ExchangeRatesInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
final class Client implements ExchangeRatesInterface
{
public function __construct(
private readonly string $baseUrl,
private readonly HttpClient $client,
private readonly SerializerInterface $serializer,
) {}
/**
* @throws GuzzleException
* @link https://exchangeratesapi.io/documentation/
*/
public function latest(): Rates
{
$url = "$this->baseUrl/latest";
$response = $this->client->get($url);
return $this->serializer->deserialize(
$response->getBody()->getContents(),
Rates::class,
JsonEncoder::FORMAT
);
}
}