diff --git a/src/Client.php b/src/Client.php index bd8cb09..e031635 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,16 +29,19 @@ class Client{ curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - if($type!='GET'){ + if($type!='GET' && $type!='FORM'){ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); } - - if (!is_null($postFields)) { - $postFields = json_encode($postFields); + if(!is_null($postFields)) { + if($type=='FORM'){ + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']); + }else{ + $postFields = json_encode($postFields); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', + 'Content-Length: '.strlen($postFields), ]); + } curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', - 'Content-Length: '.strlen($postFields), ]); } if($this->user) { curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); diff --git a/src/Repo.php b/src/Repo.php index 683cad5..7f2798b 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -89,4 +89,11 @@ class Repo{ return new Issue($this,$data); } + public function addAttachment($path,$type='image/png'){ + $url="repos/{$this->user}/{$this->repo}/releases/1/assets?name=test"; + $args=['attachment'=>new \CurlFile($path, $type, 'filename.png')]; + $data=$this->client->request($url,'FORM',$args); + return $data; + } + }