Last active
August 29, 2015 14:06
-
-
Save markglenfletcher/6f73f27cde978ee5e470 to your computer and use it in GitHub Desktop.
This file contains 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'), | |
urls = [], | |
results = {} | |
for(var i = 2; i < process.argv.length; i++) { | |
urls.push(process.argv[i]) | |
} | |
var log_end_results = function() { | |
urls.forEach(function(url){ | |
console.log(results[url].full_response) | |
}) | |
} | |
var populate_complete_response = function(url) { | |
results[url].data_list.forEach(function(data){ | |
results[url].full_response += data | |
}) | |
} | |
var results_storage_for = function(url) { | |
return { | |
"data_list": [], | |
"full_response": '', | |
"errors": [], | |
"complete": false, | |
"data": function(data) { | |
results[url].data_list.push(data) | |
}, | |
"error": function(error) { | |
results[url].errors.push(error) | |
}, | |
"end": function(end) { | |
results[url].complete = true | |
populate_complete_response(url) | |
all_requests_complete = true | |
urls.forEach(function(individual_url){ | |
if (results[individual_url].complete == false) all_requests_complete = false | |
}) | |
if(all_requests_complete) log_end_results() | |
} | |
} | |
} | |
urls.forEach(function(url) { | |
results[url] = results_storage_for(url) | |
http.get(url,function(response) { | |
response.setEncoding = 'utf8' | |
response.on("data", results[url].data) | |
response.on("error", results[url].error) | |
response.on("end", results[url].end) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment