3 namespace seekat\API\Call
;
5 use http\Client\Response
;
8 use seekat\Exception\RequestException
;
14 function __construct(API
$api) {
18 function __invoke(Response
$response) : API
{
19 $url = $this->api
->getUrl();
20 $log = $this->api
->getLogger();
21 $log->info(($response->getHeader("X-Cache-Time") ?
"cached" : "enqueued")." -> response", [
22 "url" => (string) $url,
23 "info" => $response->getInfo(),
26 if ($response->getResponseCode() >= 400) {
27 $e = new RequestException($response);
29 $log->critical(__FUNCTION__
.": ".$e->getMessage(), [
30 "url" => (string) $url,
36 if (!($type = $response->getHeader("Content-Type", Header
::class))) {
37 $e = new RequestException($response);
39 __FUNCTION__
.": Empty Content-Type -> ".$e->getMessage(), [
40 "url" => (string) $url,
46 $type = new API\
ContentType($type);
47 $data = $type->parseBody($response->getBody());
49 if (($link = $response->getHeader("Link", Header
::class))) {
50 $links = new API\
Links($link);
55 $this->api
= $this->api
->with(compact("type", "data", "links"));
56 } catch (\Exception
$e) {
57 $log->error(__FUNCTION__
.": ".$e->getMessage(), [
58 "url" => (string) $url