flush
[pharext/pharext.org] / app / Github / Create / ReleaseAsset.php
diff --git a/app/Github/Create/ReleaseAsset.php b/app/Github/Create/ReleaseAsset.php
new file mode 100644 (file)
index 0000000..03d0d41
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace app\Github\Create;
+
+use app\Github\Create;
+use app\Github\Exception\ReleaseAssetCreateFailed;
+use http\Client\Request;
+
+class ReleaseAsset extends Create
+{
+       function getRequest() {
+               // FIXME: use uri_template extension
+               $url = str_replace("{?name}", "?name=".urlencode(basename($this->args["asset"])), $this->args["url"]);
+               $body = new \http\Message\Body(fopen($this->args["asset"], "rb"));
+               $request = new Request("POST", $url, [
+                       "Accept" => "application/vnd.github.v3+json",
+                       "Content-Type" => $this->args["type"],
+                       "Authorization" => "token ". $this->api->getToken()
+               ], $body);
+               return $request;
+       }
+       
+       function getException($message, $code, $previous = null) {
+               return new ReleaseAssetCreateFailed($message, $code, $previous);
+       }
+}