-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
381 lines (336 loc) · 9.29 KB
/
index.js
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
'use strict';
const GitHub = require('github-base');
/**
* The main export is the `Gists` class. Start by creating an instance of `Gists`.
*
* ```js
* // see github-base for all available options and other ways to authenticate
* const Gists = require('gists');
* const gists = new Gists({ username: 'your_username', password: '*******' });
*
* // all methods, when invoked, return a promise with this sigature
* gists.get(...args)
* .then(res => console.log(res.body))
* .catch(console.error);
* ```
* @class
* @name Gists
* @param {Object} `options`
* @api public
*/
class Gists extends GitHub {
/**
* Create a new gist ([docs][create_gist]).
*
* ```js
* // POST /gists
* gists.create(options);
* ```
* @name .create
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
create(options) {
return this.post('/gists', options);
}
/**
* Get a gist ([docs][get_gist]).
*
* ```js
* // GET /gists/:gist_id
* gists.get(gist_id[, options]);
* ```
* @name .get
* @param {String} `gist_id` (required) The id of the gist to get.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
get(gist_id, options) {
return super.get(`/gists/${gist_id}`, options);
}
/**
* List all gists for the given `username` ([docs][list_gists]).
*
* ```js
* // GET /users/:username/gists
* gists.list(username[, options]);
* ```
* @name .list
* @param {String} `username`
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
list(username, options) {
return super.get(`/users/${username}/gists`, options);
}
/**
* List the authenticated user's gists, or if called anonymously get all
* public gists. ([docs][list_gists]).
*
* ```js
* // GET /gists/
* gists.all(options);
* ```
* @name .all
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
all(options) {
return this.paged('/gists', options);
}
/**
* List all public gists sorted by most recently updated to least
* recently updated ([docs][list_public]).
*
* ```js
* // GET /gists/public
* gists.public(options);
* ```
* @name .public
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
public(options) {
return this.paged('/gists/public', options);
}
/**
* List the authenticated user's starred gists ([docs][list_starred]).
*
* ```js
* // GET /gists/starred
* gists.starred(options);
* ```
* @name .starred
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
starred(options) {
return super.get('/gists/starred', options);
}
/**
* Get a specific revision of a gist ([docs][get_revision]).
*
* ```js
* // GET /gists/:gist_id/:sha
* gists.revision(gist_id, sha[, options]);
* ```
* @name .revision
* @param {String} `gist_id` (required) The id of the gist to get.
* @param {String} `sha` (required) The `sha` of the gist revision to get.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
revision(gist_id, sha, options) {
return super.get(`/gists/${gist_id}/${sha}`, options);
}
/**
* List commits for a gist ([docs][list_gist_commits]).
*
* ```js
* // GET /gists/:gist_id/commits
* gists.commit(gist_id[, options]);
* ```
* @name .commits
* @param {String} `gist_id` (required) The id of the gist to get commits for.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
commits(gist_id, options) {
return super.get(`/gists/${gist_id}/commits`, options);
}
/**
* List all forks for a gist ([docs][list_gist_forks]).
*
* ```js
* // GET /gists/:gist_id/forks
* gists.forks(gist_id[, options]);
* ```
* @name .forks
* @param {String} `gist_id` (required) The id of the gist to list forks for.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
forks(gist_id, options) {
return super.get(`/gists/${gist_id}/forks`, options);
}
/**
* Fork a gist ([docs][fork_gist]).
*
* ```js
* // POST /gists/:gist_id/forks
* gists.fork(gist_id[, options]);
* ```
* @name .fork
* @param {String} `gist_id` The id of the gist to fork.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
fork(gist_id, options) {
return super.post(`/gists/${gist_id}/forks`, options);
}
/**
* Edit a gist ([docs][edit_gist]).
*
* ```js
* // PATCH /gists/:gist_id
* gists.edit(gist_id[, options]);
* ```
* @name .edit
* @param {String} `gist_id` (required) The id of the gist to edit.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
edit(gist_id, options) {
return super.patch(`/gists/${gist_id}`, options);
}
/**
* Delete a gist ([docs][delete_gist]).
*
* ```js
* // DELETE /gists/:gist_id
* gists.delete(gist_id[, options]);
* ```
* @name .delete
* @param {String} `gist_id` (required) The id of the gist to delete.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
delete(gist_id, options) {
return super.delete(`/gists/${gist_id}`, options);
}
/**
* Star a gist ([docs][star_gist]).
*
* ```js
* // PUT /gists/:gist_id/star
* gists.star(gist_id[, options]);
* ```
* @name .star
* @param {String} `gist_id` (required) The id of the gist to star.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
star(gist_id, options) {
return this.put(`/gists/${gist_id}/star`, options);
}
/**
* Unstar a gist ([docs][unstar_gist]).
*
* ```js
* // DELETE /gists/:gist_id/star
* gists.unstar(gist_id[, options]);
* ```
* @name .unstar
* @param {String} `gist_id` (required) The id of the gist to unstar.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
unstar(gist_id, options) {
return super.delete(`/gists/${gist_id}/star`, options);
}
/**
* Check if a gist is starred ([docs][is_starred]).
*
* ```js
* // GET /gists/:gist_id/star
* gists.isStarred(gist_id[, options])
* ```
* @name .isStarred
* @param {String} `gist_id` (required) The id of the gist to check.
* @param {Object} `options` Options to pass to [github-base][].
* @return {Boolean} Returns `true` if a gist is starred.
* @api public
*/
isStarred(gist_id, options) {
return super.get(`/gists/${gist_id}/star`, options)
.then(res => true)
.catch(err => {
if (err.res.statusCode !== 404) {
return Promise.resolve(err);
}
return false;
});
}
/**
* Create a comment on a gist ([docs][create_comment]).
*
* ```js
* // POST /gists/:gist_id/comments
* gists.comment(gist_id, { body: 'Just commenting for the sake of commenting' });
* ```
* @name .comment
* @param {String} `gist_id` (required)
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
createComment(gist_id, options) {
return super.post(`/gists/${gist_id}/comments`, options);
}
/**
* Get a single comment from a gist ([docs][get_comment]).
*
* ```js
* // GET /gists/:gist_id/comments/:comment_id
* gists.getComment(gist_id, comment_id, options);
* ```
* @name .getComment
* @param {String} `gist_id` (required)
* @param {String} `comment_id` (required) The id of the comment to get.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
getComment(gist_id, comment_id, options) {
return super.get(`/gists/${gist_id}/comments/${comment_id}`, options);
}
/**
* List comments on a gist ([docs][list_comments]).
*
* ```js
* // GET /gists/:gist_id/comments
* gists.listComments(options);
* ```
* @name .listComments
* @param {String} `gist_id` (required)
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
listComments(gist_id, options) {
return super.get(`/gists/${gist_id}/comments`, options);
}
/**
* Edit a comment ([docs][edit_comment]).
*
* ```js
* // PATCH /gists/:gist_id/comments/:gist_id
* gists.editComment(gist_id, comment_id[, options]);
* ```
* @name .edit
* @param {String} `gist_id` (required)
* @param {String} `comment_id` (required) The id of the comment to edit.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
editComment(gist_id, comment_id, options) {
return this.patch(`/gists/${gist_id}/comments/${comment_id}`, options);
}
/**
* Delete a comment ([docs][delete_comment]).
*
* ```js
* // DELETE /gists/:gist_id/comments/:comment_id
* gists.deleteComment(gist_id, comment_id[, options]);
* ```
* @name .delete
* @param {String} `gist_id` (required)
* @param {String} `comment_id` (required) The id of the comment to edit.
* @param {Object} `options` Options to pass to [github-base][].
* @api public
*/
deleteComment(gist_id, comment_id, options) {
return this.delete(`/gists/${gist_id}/comments/${comment_id}`, options);
}
}
/**
* Expose `Gists` class
*/
module.exports = Gists;