refactor guthub api
[pharext/pharext.org] / app / Github / API / Repos / ReadRepo.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 http\Client\Request;
8
9 class ReadRepo extends Call
10 {
11 function enqueue(callable $callback) {
12 $url = $this->url->mod(uri_template("./repos/{+repo}", $this->args));
13 $request = new Request("GET", $url, [
14 "Authorization" => "token " . $this->api->getToken(),
15 "Accept" => $this->config->api->accept,
16 ]);
17 $this->api->getClient()->enqueue($request, function($response) use($callback) {
18 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
19 throw new RequestException($response);
20 }
21 $this->saveToCache($json);
22 $callback($json);
23 return true;
24 });
25 }
26 }