Last active
August 29, 2015 14:27
-
-
Save avdg/647f7468ff39547d647f 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
"use strict"; | |
var https = require("https"); | |
var querystring = require("querystring"); | |
// Display help if necessary | |
if ((process.argv[2] === "--help" || process.argv[2] === undefined) && process.argv[3] === undefined) { | |
console.log("Usage: " + process.argv[0] + " " + process.argv[1] + " <email> <password> [branch=default]"); | |
process.exit(); | |
} | |
// Fetch parameters | |
var user = process.argv[2]; | |
var pass = process.argv[3]; | |
var branch = process.argv[4]; | |
if (typeof branch !== "string") { | |
branch = "default"; | |
} | |
// Build request data | |
var query = querystring.stringify({ | |
branch: branch | |
}); | |
var request = { | |
hostname: 'screeps.com', | |
port: 443, | |
path: '/api/user/code?' + query, | |
method: 'GET', | |
auth: user + ':' + pass | |
}; | |
console.log(request.path); | |
// Request data | |
https.get(request, function(res) { | |
var data = ""; | |
res.on('data', function(chunk) { | |
data += chunk; | |
}); | |
res.on('end', function() { | |
console.log(data); // TODO Do whatever you want, the code is json packed though, code is available under key "modules" | |
}); | |
}).on('error', function(e) { | |
console.log("Can't fetch code: " + e.toString() + "\n\n" + e.message + "\n\n" + Object.keys(e)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment