bookinventory/app/Services/BookInformation/GoogleBooks.php

31 lines
810 B
PHP
Raw Normal View History

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
2020-12-27 00:34:07 +00:00
return (object) [
2020-12-21 07:09:34 +00:00
'title' => $volume->getTitle(),
2020-12-27 00:34:07 +00:00
'authors' => $volume->getAuthors(),
'images' => $volume->getImageLinks(),
2020-12-21 07:09:34 +00:00
];
}
}