Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pdp\Storage;
|
||||
|
||||
use Pdp\TopLevelDomainList;
|
||||
use Pdp\TopLevelDomains;
|
||||
use Pdp\UnableToLoadResource;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\RequestFactoryInterface;
|
||||
|
||||
final class TopLevelDomainListPsr18Client implements TopLevelDomainListClient
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ClientInterface $client,
|
||||
private readonly RequestFactoryInterface $requestFactory
|
||||
) {
|
||||
}
|
||||
|
||||
public function get(string $uri): TopLevelDomainList
|
||||
{
|
||||
$request = $this->requestFactory->createRequest('GET', $uri);
|
||||
try {
|
||||
$response = $this->client->sendRequest($request);
|
||||
} catch (ClientExceptionInterface $exception) {
|
||||
throw UnableToLoadResource::dueToUnavailableService($uri, $exception);
|
||||
}
|
||||
|
||||
if (400 <= $response->getStatusCode()) {
|
||||
throw UnableToLoadResource::dueToUnexpectedStatusCode($uri, $response->getStatusCode());
|
||||
}
|
||||
|
||||
return TopLevelDomains::fromString($response->getBody());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user