Skip to content

Instantly share code, notes, and snippets.

@CiscoKidxx
Created June 22, 2017 18:21
Show Gist options
  • Save CiscoKidxx/2695f932051a4151a72e150e982ede56 to your computer and use it in GitHub Desktop.
Save CiscoKidxx/2695f932051a4151a72e150e982ede56 to your computer and use it in GitHub Desktop.
const request = require('request'),
prompt = require('prompt'),
async = require('async');
async.waterfall([
getInput,
queryApi
], function(err, result) {
console.log(result);
});
function getInput(callback) {
prompt.start();
prompt.get(['dnis'],  function (err,  result)  {
if (result.dnis === '') {
console.log('You must enter a dnis to query API')
process.exit()
} else {
let dnis = result.dnis;
callback(null, dnis);
}
});
}
function queryApi(dnis, callback) {
request({
url: 'https://api.smilegeneration.com/callcenterinfo/?id=' + dnis,
"rejectUnauthorized": false
},
function(error, response, body) {
if (response.statusCode === 200) {
let parsedBody = JSON.parse(body)
callback(null, parsedBody);
} else {
callback(null, body)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment