promise refactoring++
[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\Client\Response;
9 use http\Message\Body;
10
11 class CreateReleaseAsset extends Call
12 {
13 function request() {
14 $body = new Body(fopen($this->args["asset"], "rb"));
15 $request = new Request("POST", $this->args["url"], [
16 "Authorization" => "token ". $this->api->getToken(),
17 "Accept" => $this->config->api->accept,
18 "Content-Type" => $this->args["type"],
19 ], $body);
20 return $request;
21 }
22
23 function response(Response $response) {
24 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
25 throw new RequestException($response);
26 }
27 return [$json];
28 }
29 }