-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
45 lines (39 loc) · 834 Bytes
/
github.js
File metadata and controls
45 lines (39 loc) · 834 Bytes
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
var http = require('http')
, xml = require('xml2json')
, bot
, options = {
host : ''
, path : ''
, method : 'GET'
}
, time = 1000 * 60 * 1 // 1 Minute
exports.init = function(_bot) {
bot = _bot
options.host = bot.config.github.host
options.path = bot.config.github.path
makeRequests()
}
function makeRequests() {
var req = http.request(options, gotResults)
req.end()
req.on('error', gotError)
}
function gotResults(res) {
var data = ''
res.on('data', function(chunk) {
data += chunk
})
res.on('end', function() {
try {
data = JSON.parse(xml.toJson(data))
} catch(e) {
return gotError(e)
}
bot.controller.githubFeed(data)
setTimeout(makeRequests, time)
})
}
function gotError(error) {
console.log(error)
setTimeout(makeRequests, time)
}