Skip to content

Instantly share code, notes, and snippets.

@CiscoKidxx
Last active June 22, 2017 21:17
Show Gist options
  • Save CiscoKidxx/7c488abd27dde6fa2f12be6d250d4f16 to your computer and use it in GitHub Desktop.
Save CiscoKidxx/7c488abd27dde6fa2f12be6d250d4f16 to your computer and use it in GitHub Desktop.
const request = require('request'),
prompt = require('prompt'),
async = require('async');
let main = function() {
return async.waterfall([
getInput,
queryApi
], function(err, result) {
console.log(result);
if (!err) {
main();
}
});
}
function getInput(callback) {
prompt.start();
prompt.get(['office'],  function (err,  result)  {
if (result.office === '') {
console.log('You must enter an office # to query API')
process.exit()
} else {
let office = result.office;
callback(null, office);
}
});
}
function queryApi(officeInput, callback) {
request({
url: 'https://cms-marketing-repo-development.dev.pdsconnect.com/callCenterInfo/',
"rejectUnauthorized": false
},
function(error, response, body) {
if (response.statusCode === 200) {
let offices = JSON.parse(body)
function findOffice(o) {
return o.OfficeId == officeInput;
}
let officeDetail = offices.find(findOffice)
callback(null, officeDetail);
} else {
callback(null, body)
}
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment