-
Notifications
You must be signed in to change notification settings - Fork 0
/
githubApi.js
46 lines (40 loc) · 1.16 KB
/
githubApi.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
var auth = require('./auth.js');
var jwt = require('jsonwebtoken');
var redis = require('./redis.js');
var https = require('https');
var fs = require('fs');
var issues = fs.readFileSync(__dirname + '/public/html/issues.html');
var api = module.exports = {};
api.getIssues = function(jToken, callback) {
var decodedJWT = jwt.decode(jToken);
var username = decodedJWT.auth;
redis.getAccessToken(username, function(githubAccessToken) {
var options = {
host: 'api.github.com',
path: '/issues?filter=assigned&state=open',
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
'Authorization': 'token '+githubAccessToken
}
};
var issuesReq = https.request(options, function(res) {
parseBody(res, function(body) {
callback(body);
});
});
issuesReq.end();
});
};
function parseBody(object, callback) {
var body = "";
object.on('data', function(data) {
body += data;
});
object.on('end', function() {
callback(body);
});
object.on('error', function(e) {
console.log("Got error: " + e.message);
});
}