03d0d415ea0d86d65a69865e2ff040933bd72491
[pharext/pharext.org] / app / Github / Create / ReleaseAsset.php
1 <?php
2
3 namespace app\Github\Create;
4
5 use app\Github\Create;
6 use app\Github\Exception\ReleaseAssetCreateFailed;
7 use http\Client\Request;
8
9 class ReleaseAsset extends Create
10 {
11 function getRequest() {
12 // FIXME: use uri_template extension
13 $url = str_replace("{?name}", "?name=".urlencode(basename($this->args["asset"])), $this->args["url"]);
14 $body = new \http\Message\Body(fopen($this->args["asset"], "rb"));
15 $request = new Request("POST", $url, [
16 "Accept" => "application/vnd.github.v3+json",
17 "Content-Type" => $this->args["type"],
18 "Authorization" => "token ". $this->api->getToken()
19 ], $body);
20 return $request;
21 }
22
23 function getException($message, $code, $previous = null) {
24 return new ReleaseAssetCreateFailed($message, $code, $previous);
25 }
26 }