2020-12-21 07:09:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Cache;
|
|
|
|
use App\Services\BookInformation\GoogleBooks;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
|
|
|
|
class LookupController {
|
|
|
|
public function lookup($isbn) {
|
|
|
|
if (!preg_match('/^(\d+)$/', $isbn)) {
|
|
|
|
throw new HttpException(400);
|
|
|
|
}
|
|
|
|
|
2020-12-21 07:21:20 +00:00
|
|
|
return Cache::remember('isbn_' . $isbn, 86400, function() use ($isbn) {
|
2020-12-21 07:09:34 +00:00
|
|
|
$google_books = new GoogleBooks();
|
|
|
|
|
|
|
|
return $google_books->lookup($isbn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|