-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathGists.php
More file actions
182 lines (160 loc) · 3.65 KB
/
Gists.php
File metadata and controls
182 lines (160 loc) · 3.65 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace Github\Api;
use Github\Api\Gist\Comments;
use Github\Exception\MissingArgumentException;
/**
* Creating, editing, deleting and listing gists.
*
* @link http://developer.github.com/v3/gists/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Edoardo Rivello <edoardo.rivello at gmail dot com>
*/
class Gists extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/gists/#custom-media-types
*
* @param string|null $bodyType
*
* @return $this
*/
public function configure($bodyType = null)
{
if ('base64' !== $bodyType) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s', $bodyType);
return $this;
}
/**
* @param string|null $type
*
* @return array|string
*/
public function all($type = null)
{
if (!in_array($type, ['public', 'starred'])) {
return $this->get('/gists');
}
return $this->get('/gists/'.rawurlencode($type));
}
/**
* @param string $number
*
* @return array
*/
public function show($number)
{
return $this->get('/gists/'.rawurlencode($number));
}
/**
* Get a specific revision of a gist.
*
* @param string $number
* @param string $sha
*
* @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
*
* @return array
*/
public function revision($number, $sha)
{
return $this->get('/gists/'.rawurlencode($number).'/'.rawurlencode($sha));
}
public function create(array $params)
{
if (!isset($params['files']) || (!is_array($params['files']) || 0 === count($params['files']))) {
throw new MissingArgumentException('files');
}
$params['public'] = (bool) $params['public'];
return $this->post('/gists', $params);
}
/**
* @param string $id
* @param array $params
*
* @return array
*/
public function update($id, array $params)
{
return $this->patch('/gists/'.rawurlencode($id), $params);
}
/**
* @param string $id
*
* @return array
*/
public function commits($id)
{
return $this->get('/gists/'.rawurlencode($id).'/commits');
}
/**
* @param string $id
*
* @return array
*/
public function fork($id)
{
return $this->post('/gists/'.rawurlencode($id).'/fork');
}
/**
* @param string $id
*
* @return array
*/
public function forks($id)
{
return $this->get('/gists/'.rawurlencode($id).'/forks');
}
/**
* @param string $id
*
* @return array
*/
public function remove($id)
{
return $this->delete('/gists/'.rawurlencode($id));
}
/**
* @param string $id
*
* @return array
*/
public function check($id)
{
return $this->get('/gists/'.rawurlencode($id).'/star');
}
/**
* @param string $id
*
* @return array
*/
public function star($id)
{
return $this->put('/gists/'.rawurlencode($id).'/star');
}
/**
* @param string $id
*
* @return array
*/
public function unstar($id)
{
return $this->delete('/gists/'.rawurlencode($id).'/star');
}
/**
* Get a gist's comments.
*
* @link http://developer.github.com/v3/gists/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->getClient());
}
}