Repository navigation
Expand file tree
/
Copy pathAssets.php
More file actions
117 lines (107 loc) · 4.25 KB
/
Copy pathAssets.php
File metadata and controls
117 lines (107 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\ErrorException;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/releases/
* @author Evgeniy Guseletov <d46k16@gmail.com>
*/
class Assets extends AbstractApi
{
/**
* Get all release's assets in selected repository
* GET /repos/:owner/:repo/releases/:id/assets.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
*
* @return array
*/
public function all($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets');
}
/**
* Get an asset in selected repository's release
* GET /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}
/**
* Create an asset for selected repository's release
* POST /repos/:owner/:repo/releases/:id/assets?name=:filename.
*
* Creating an asset requires support for server name indentification (SNI)
* so this must be supported by your PHP version.
*
* @see http://developer.github.com/v3/repos/releases/#upload-a-release-asset
* @see http://php.net/manual/en/openssl.constsni.php
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
* @param string $name the filename for the asset
* @param string $contentType the content type for the asset
* @param string $content the content of the asset
*
* @throws MissingArgumentException
* @throws ErrorException
*
* @return array
*/
public function create($username, $repository, $id, $name, $contentType, $content)
{
if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) {
throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported by your PHP version. See http://php.net/manual/en/openssl.constsni.php.');
}
// Asset creation requires a separate endpoint, uploads.github.com.
// Change the base url for the HTTP client temporarily while we execute
// this request.
$response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, array('Content-Type' => $contentType));
return $response;
}
/**
* Edit an asset in selected repository's release
* PATCH /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
* @param array $params request parameters
*
* @throws MissingArgumentException
*
* @return array
*/
public function edit($username, $repository, $id, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params);
}
/**
* Delete an asset in selected repository's release
* DELETE /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
*
* @return array
*/
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}
}