X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=lib%2FAPI.php;h=a0474122cd78e67b0d24df24c72ced3032e5e7ce;hp=546dd88da0441c35332c504e5eba3158899c684a;hb=e368287b3cd2dd40945ac8d1a1946bc32268007d;hpb=f4aa6beaf2e1f0dc9c877782cbbad5a989194517 diff --git a/lib/API.php b/lib/API.php index 546dd88..a047412 100644 --- a/lib/API.php +++ b/lib/API.php @@ -25,52 +25,52 @@ class API implements IteratorAggregate, Countable { private $url; /** - * Logger - * @var LoggerInterface + * Default headers to send out to the API endpoint + * @var array */ - private $logger; + private $headers; /** - * Cache - * @var Call\Cache\Service + * Current endpoints links + * @var Links */ - private $cache; + private $links; /** - * Promisor - * @var Future + * Current endpoint data's Content-Type + * @var API\ContentType */ - private $future; + private $type; /** - * The HTTP client - * @var Client + * Current endpoint's data + * @var array|object */ - private $client; + private $data; /** - * Default headers to send out to the API endpoint - * @var array + * Logger + * @var LoggerInterface */ - private $headers; + private $logger; /** - * Current endpoint data's Content-Type - * @var API\ContentType + * Cache + * @var Call\Cache\Service */ - private $type; + private $cache; /** - * Current endpoint's data - * @var array|object + * Promisor + * @var Future */ - private $data; + private $future; /** - * Current endpoints links - * @var Links + * The HTTP client + * @var Client */ - private $links; + private $client; /** * Create a new API endpoint root @@ -165,7 +165,9 @@ class API implements IteratorAggregate, Countable { function __invoke($cbg) : Promise { $this->logger->debug(__FUNCTION__); - $consumer = new Consumer($this->client); + $consumer = new Consumer($this->getFuture(), function() { + $this->client->send(); + }); invoke: if ($cbg instanceof Generator) { @@ -273,7 +275,7 @@ class API implements IteratorAggregate, Countable { function export() : array { $data = $this->data; $url = clone $this->url; - $type = clone $this->type; + $type = $this->type ? clone $this->type : null; $links = $this->links ? clone $this->links : null; $headers = $this->headers; return compact("url", "data", "type", "links", "headers"); @@ -355,6 +357,17 @@ class API implements IteratorAggregate, Countable { return $that; } + /** + * Perform a HEAD request against the endpoint's underlying URL + * + * @param mixed $args The HTTP query string parameters + * @param array $headers The request's additional HTTP headers + * @return Promise + */ + function head($args = null, array $headers = null, $cache = null) : Promise { + return $this->request("HEAD", $args, null, $headers, $cache); + } + /** * Perform a GET request against the endpoint's underlying URL *