Source: gst/fetch-gst.js

/**
 @fileOverview    


Fetch GST Package

Implements boilerplate prompting/connecting for GST fetch programs

Typical Usage:
```
var gst = require('./fetch-gst');

gst.main(function DownloadStuff(parameters) {
   gst.connect(parameters, function(client, auth)) {
      client.GetStuff({{Acad_Org: parameters.Acad_Org, AuthCode: auth}, ...)
   })
})
```

*/


const gst_url = 'https://netprod.its.fsu.edu/CSGST_Service/CSGST_Service.asmx?WSDL';
// for development:
// const gst_url = 'https://netdev.its.fsu.edu/CSGST_Service/CSGST_Service.asmx?WSDL';

exports.connect = function(credentials, callback) {
	const soap = require('strong-soap').soap;

	soap.createClient(gst_url, {}, function(err, client) {
		if (err) throw err;
		client.Login(credentials, function(err, result, envelope, soapHeader) {
			if (err) throw err;
			if (!result.LoginResult.isOK) throw new Error('GST Error: ' + result.LoginResult.ErrorMessage);
			callback(client, result.LoginResult.Response);
		});
	});
}

exports.main = function(callback) {
	
	if (typeof process.argv[2] == "undefined")  {
	    console.error("You must specify the academic organization, eg ASBIO, as a command line argument");
	    console.error("USAGE: node " + process.argv[1] + " <ACADORG>  [<fsuid>  <password>]");
	    process.exit(1);
	}

	const parameters = {Acad_Org: process.argv[2]};

	if (typeof process.argv[4] != "undefined")  {
		callback({...parameters, ...{FSUID: process.argv[3], Password: process.argv[4]}});
	} else {

		const prompt = require('prompt');
		prompt.message = "";
		prompt.start();
		prompt.get([{
		      name: 'FSUID',
		      required: true
		    }, {
		      name: 'Password',
		      hidden: true,
		      replace: '*'
		}],
		function (err, result) {
			if (err) throw err;
			callback({...parameters, ...result});
		});
	}
}