bookinventory/app/Services/BookInformation/GoogleBooks.php

29 lines
723 B
PHP

<?php
namespace App\Services\BookInformation;
use Google_Client;
use Google_Service_Books;
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 = array_first($results->getItems())->getVolumeInfo();
return [
'title' => $volume->getTitle(),
'authors' => $volume->getAuthors()
];
}
}