feat(service): add api service
This commit is contained in:
35
src/Service/Remote/BriloApiComments.php
Normal file
35
src/Service/Remote/BriloApiComments.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user