refactor guthub api
[pharext/pharext.org] / app / Github / API / Releases / CreateReleaseAsset.php
1 <?php
2
3 namespace app\Github\API\Releases;
4
5 use app\Github\API\Call;
6 use app\Github\Exception\RequestException;
7 use http\Client\Request;
8 use http\Message\Body;
9
10 class CreateReleaseAsset extends Call
11 {
12 function enqueue(callable $callback) {
13 $body = new Body(fopen($this->args["asset"], "rb"));
14 $request = new Request("POST", $this->args["url"], [
15 "Authorization" => "token ". $this->api->getToken(),
16 "Accept" => $this->config->api->accept,
17 "Content-Type" => $this->args["type"],
18 ], $body);
19 $this->api->getClient()->enqueue($request, function($response) use($callback) {
20 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
21 throw new RequestException($response);
22 }
23 $callback($json);
24 return true;
25 });
26 }
27 }