bookinventory/app/Services/BookInformation/GoogleBooks.php
Tyler a1ac81a73a
All checks were successful
continuous-integration/drone/push Build is passing
Add attachments, more pages
2020-12-26 19:34:07 -05:00

31 lines
810 B
PHP

<?php
namespace App\Services\BookInformation;
use Google_Client;
use Google_Service_Books;
use Illuminate\Support\Arr;
class GoogleBooks implements BookLookupService {
public function lookup($isbn) {
$client = new Google_Client();
$client->setApplicationName("BookInventory");
$client->setDeveloperKey(env('GOOGLE_BOOKS_KEY'));
$service = new Google_Service_Books($client);
$results = $service->volumes->listVolumes('isbn:' . $isbn);
/**
* @var \Google_Service_Books_Volume
*/
$volume = Arr::first($results->getItems())->getVolumeInfo();
return (object) [
'title' => $volume->getTitle(),
'authors' => $volume->getAuthors(),
'images' => $volume->getImageLinks(),
];
}
}