feat(service): add api service

This commit is contained in:
2024-07-29 18:50:58 +02:00
parent e929853bb2
commit e1375f1bf5
18 changed files with 639 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Service\Remote;
use App\Entity\Remote\Brilo\Comments\Comment;
use App\Entity\Remote\Brilo\Posts\Post;
use Psr\Log\LoggerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class BriloApiComments
{
use BriloApiFetchTrait;
public function __construct(
protected readonly HttpClientInterface $httpClient,
protected readonly LoggerInterface $logger,
protected readonly SerializerInterface $serializer,
protected readonly int $retryCount = 3,
protected readonly int $sleepTimeS = 1,
) {
}
/**
* Fetch all comments from the Brilo API and return them as an array of Comment entities.
* @return Comment[]
* @throws \Exception
*/
public function getComments(): array
{
return $this->fetchApiResponse('https://jsonplaceholder.typicode.com/comments', Comment::class);
}
}