Skip to content

Instantly share code, notes, and snippets.

@avdg
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdg/647f7468ff39547d647f to your computer and use it in GitHub Desktop.
Save avdg/647f7468ff39547d647f to your computer and use it in GitHub Desktop.
"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