Files
BookNest/src/services/GoogleService.php
Kilian Beraud 31f64b9e5a - Ajout d'une pagination
- Résultats plu pertinent, affichage des livres seulement
2025-01-30 09:19:46 +01:00

35 lines
857 B
PHP

<?php
namespace App\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class GoogleBooksService
{
private HttpClientInterface $client;
public function __construct(HttpClientInterface $client)
{
$this->client = $client;
}
public function searchBooks(string $query, string $lang = 'fr', string $nb_pages): array
{
$url = 'https://www.googleapis.com/books/v1/volumes';
$response = $this->client->request('GET', $url, [
'query' => [
'q' => $query,
'langRestrict' => $lang,
'maxResults' => 10,
'startIndex' => $nb_pages,
'printType' => 'books',
],
]);
// Convertir la réponse JSON en tableau PHP
$dataArray = $response->toArray();
return $dataArray;
}
}