diff --git a/bin/server.js b/bin/server.js index 4b6fb51..0950a4c 100755 --- a/bin/server.js +++ b/bin/server.js @@ -17,23 +17,22 @@ var POLL_INTERVAL = 10000; // our news object that we'll diff against var shared_news_obj = []; +// grabs news from unofficial HN API (http://api.ihackernews.com) +// and fires the 'new_news' event. function get_news() { sys.puts("fetching news..."); - request({uri:'http://api.ihackernews.com/page'}, function (error, response, data) { if (!error && response.statusCode == 200) { - - //sys.puts("response:"); - //sys.puts(data); - var news_obj = JSON.parse(data); if(news_obj.items && news_obj.items.length > 0) { - // diff the two to see if anything new has shown up. + // TODO: diff the two to see if anything new has shown up as + // opposed to just firing the event blindly. - sys.puts("found some news! (" + news_obj.items.length + ")"); + sys.puts("found some news!"); news_emitter.emit('new_news', news_obj.items); - - + } + else { + sys.puts("couldn't find news :("); } } }); @@ -61,7 +60,7 @@ socket.on('connection', function(client){ // New news callback/listener. Send it when we see it. var handleNews = function(news) { - sys.puts("sending message..."); + //sys.puts("sending message..."); // Give the message a type, so the FE can act on various different // messages should the need arise.