Add Attachment support

This commit is contained in:
James 2019-09-23 12:14:59 +01:00
parent a2c44392b2
commit aef0c2166e
2 changed files with 16 additions and 6 deletions

View File

@ -29,17 +29,20 @@ 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)) {
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_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $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);
}
if($this->user) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);

View File

@ -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;
}
}