2020-12-21 07:09:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\BookInformation;
|
|
|
|
|
|
|
|
use Google_Client;
|
|
|
|
use Google_Service_Books;
|
2020-12-21 07:33:51 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2020-12-21 07:09:34 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2020-12-21 07:33:51 +00:00
|
|
|
$volume = Arr::first($results->getItems())->getVolumeInfo();
|
2020-12-21 07:09:34 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
'title' => $volume->getTitle(),
|
|
|
|
'authors' => $volume->getAuthors()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|