Last active
August 29, 2015 14:14
-
-
Save bjeavons/35b484f3c45a74db2766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var cheerio = require('cheerio'); | |
function parse_feed (content, hook, callback) { | |
$ = cheerio.load(content); | |
$('entry').each(function(i, elem) { | |
hook.debug($(this).find('title').text()); | |
}); | |
callback(); | |
} | |
module['exports'] = function collect (hook) { | |
hook.debug(hook.params); | |
hook.debug(hook.req.path); | |
hook.debug(hook.req.method); | |
hook.debug(hook.env); | |
var url = 'http://www.vox.com/rss/vox-sentences/index.xml'; | |
http.get(url, function(response){ | |
hook.debug("Success") | |
var body = ''; | |
response.on('data', function(chunk) { | |
body += chunk; | |
}); | |
response.on("end", function() { | |
//hook.debug("BODY: " + body); | |
parse_feed(body, hook, function() { | |
hook.res.end('OK ' + JSON.stringify(hook.params, true, 2)); | |
}); | |
//hook.res.end('OK ' + JSON.stringify(hook.params, true, 2)); | |
}); | |
}).on('error', function (){ | |
hook.debug("Error getting VS feed") | |
hook.res.end('error ' + JSON.stringify(hook.params, true, 2)); | |
}); | |
}; | |
module['exports'].schema = { | |
"data": { | |
"type": "string" | |
}, | |
"title": { | |
"type": "string" | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment