Created
June 22, 2017 18:21
-
-
Save CiscoKidxx/2695f932051a4151a72e150e982ede56 to your computer and use it in GitHub Desktop.
This file contains 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
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