forked from kevva/github-gists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 755 Bytes
/
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
'use strict';
var ghGot = require('gh-got');
var page = 1;
var ret = [];
function getGists(user, opts, cb) {
var url = 'users/' + user + '/gists?per_page=100&page=' + page;
ghGot(url, opts, function (err, data, res) {
if (err) {
cb(err);
return;
}
ret = ret.concat(data);
if (res.headers.link && res.headers.link.indexOf('next') !== -1) {
page++;
getGists(user, opts, cb);
return;
}
cb(null, ret);
});
}
module.exports = function (user, opts, cb) {
opts = opts || {};
if (typeof user !== 'string') {
throw new Error('User required');
}
if (typeof opts !== 'object') {
cb = opts;
opts = {};
}
getGists(user, opts, function (err, data) {
if (err) {
cb(err);
return;
}
cb(null, data);
});
};