go logging
[pharext/pharext.org] / app / Github / API / Repos / ListRepos.php
1 <?php
2
3 namespace app\Github\API\Repos;
4
5 use app\Github\API\Call;
6 use app\Github\Exception\RequestException;
7 use app\Github\Links;
8 use http\Client\Request;
9
10 class ListRepos extends Call
11 {
12 function enqueue(callable $callback) {
13 $url = $this->url->mod(uri_template("./user/repos{?page,per_page}", $this->args));
14 $request = new Request("GET", $url, [
15 "Authorization" => "token ". $this->api->getToken(),
16 "Accept" => $this->config->api->accept,
17 ]);
18 $this->api->getClient()->enqueue($request, function($response) use($callback) {
19 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
20 throw new RequestException($response);
21 }
22 $links = new Links($response->getHeader("Link"));
23 $this->saveToCache([$json, $links]);
24 $callback($json, $links);
25 return true;
26 });
27 }
28 }