fix(service): make api endpoints configurable
This commit is contained in:
@@ -18,6 +18,7 @@ class BriloApiComments
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly LoggerInterface $logger,
|
||||
protected readonly SerializerInterface $serializer,
|
||||
protected readonly string $url,
|
||||
protected readonly int $retryCount = 3,
|
||||
protected readonly int $sleepTimeS = 1,
|
||||
) {
|
||||
@@ -30,6 +31,6 @@ class BriloApiComments
|
||||
*/
|
||||
public function getComments(): array
|
||||
{
|
||||
return $this->fetchApiResponse('https://jsonplaceholder.typicode.com/comments', Comment::class);
|
||||
return $this->fetchApiResponse($this->url, Comment::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace App\Service\Remote;
|
||||
use App\Entity\Remote\Brilo\Users\User;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||
use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException;
|
||||
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
@@ -33,7 +35,9 @@ trait BriloApiFetchTrait
|
||||
*/
|
||||
protected function fetchApiResponse(string $uri, string $class): array
|
||||
{
|
||||
return $this->retryingFailRequest($this->retryCount, $this->sleepTimeS, [TransportException::class, BriloRemoteApiException::class], $this->logger, function () use ($uri, $class) {
|
||||
return $this->retryingFailRequest($this->retryCount, $this->sleepTimeS, [
|
||||
TransportException::class, BriloRemoteApiException::class, NotNormalizableValueException::class, MissingConstructorArgumentsException::class
|
||||
], $this->logger, function () use ($uri, $class) {
|
||||
$this->logger->debug('Trying to download brilo users');
|
||||
|
||||
$response = $this->httpClient->request('GET', $uri);
|
||||
|
||||
@@ -18,6 +18,7 @@ class BriloApiPosts
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly LoggerInterface $logger,
|
||||
protected readonly SerializerInterface $serializer,
|
||||
protected readonly string $url,
|
||||
protected readonly int $retryCount = 3,
|
||||
protected readonly int $sleepTimeS = 1,
|
||||
) {
|
||||
@@ -30,6 +31,6 @@ class BriloApiPosts
|
||||
*/
|
||||
public function getPosts(): array
|
||||
{
|
||||
return $this->fetchApiResponse('https://jsonplaceholder.typicode.com/posts', Post::class);
|
||||
return $this->fetchApiResponse($this->url, Post::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ final class BriloApiUsers
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly LoggerInterface $logger,
|
||||
protected readonly SerializerInterface $serializer,
|
||||
protected readonly string $url,
|
||||
protected readonly int $retryCount = 3,
|
||||
protected readonly int $sleepTimeS = 1,
|
||||
) {
|
||||
@@ -31,6 +32,6 @@ final class BriloApiUsers
|
||||
*/
|
||||
public function getUsers(): array
|
||||
{
|
||||
return $this->fetchApiResponse('https://jsonplaceholder.typicode.com/users', User::class);
|
||||
return $this->fetchApiResponse($this->url, User::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user