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