first commit
This commit is contained in:
7
app/Services/BookInformation/BookLookupService.php
Normal file
7
app/Services/BookInformation/BookLookupService.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\BookInformation;
|
||||
|
||||
interface BookLookupService {
|
||||
public function lookup($isbn);
|
||||
}
|
29
app/Services/BookInformation/GoogleBooks.php
Normal file
29
app/Services/BookInformation/GoogleBooks.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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()
|
||||
];
|
||||
}
|
||||
}
|
9
app/Services/BookInformation/LookupException.php
Normal file
9
app/Services/BookInformation/LookupException.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\BookInformation;
|
||||
|
||||
use Exception;
|
||||
|
||||
class LookupException extends Exception {
|
||||
|
||||
}
|
Reference in New Issue
Block a user