tissue/app/MetadataResolver/MelonbooksResolver.php
2018-06-13 01:00:24 +09:00

22 lines
631 B
PHP

<?php
namespace App\MetadataResolver;
use GuzzleHttp\Cookie\CookieJar;
class MelonbooksResolver implements Resolver
{
public function resolve(string $url): Metadata
{
$cookieJar = CookieJar::fromArray(['AUTH_ADULT' => '1'], 'www.melonbooks.co.jp');
$client = new \GuzzleHttp\Client();
$res = $client->get($url, ['cookies' => $cookieJar]);
if ($res->getStatusCode() === 200) {
$ogpResolver = new OGPResolver();
return $ogpResolver->parse($res->getBody());
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}