33 lines
728 B
PHP
33 lines
728 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'): array
|
|
{
|
|
$url = 'https://www.googleapis.com/books/v1/volumes';
|
|
$response = $this->client->request('GET', $url, [
|
|
'query' => [
|
|
'q' => $query,
|
|
'langRestrict' => $lang,
|
|
],
|
|
]);
|
|
|
|
|
|
// Convertir la réponse JSON en tableau PHP
|
|
$dataArray = $response->toArray();
|
|
|
|
return $dataArray;
|
|
}
|
|
}
|