88b5a493bb8a1a4482b680a3a55b23902d8875ee
[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 $this->result = [$json];
24 $callback($json);
25 return true;
26 });
27 }
28 }