(function (program, flowroute) { | |
var itemsPerPage = 10; | |
var formatNumber = function (raw) { | |
return `+${raw.substring(0, 1)} (${raw.substring(1,4)}) ${raw.substring(4,7)}-${raw.substring(7,11)}`; | |
} | |
var listNPAs = function (err, npaList) { | |
if (err) { | |
console.log(err); | |
} else { | |
for (var areaCode in npaList.npas) { | |
console.log('Area Code: ' + areaCode); | |
} | |
} | |
}; | |
var listAreaAndExchange = function (err, exchangeList) { | |
if (err) { | |
console.log(err); | |
} else { | |
for (var number in exchangeList.npanxxs) { | |
console.log('Available Exchange:', number.substring(0,3), '-', number.substring(3), '- XXXX'); | |
} | |
} | |
}; | |
var searchNumbers = function (err, numberList) { | |
if (err) { | |
console.log(err); | |
} else { | |
for (var num in numberList.tns) { | |
var entry = numberList.tns[num]; | |
console.log( | |
formatNumber(num), | |
'for', | |
'$' + entry.initial_cost, | |
'then', | |
'$' + entry.monthly_cost, | |
'per month.'); | |
} | |
} | |
}; | |
var listMyNumbers = function (err, numberList) { | |
if (err) { | |
console.log(err); | |
} else { | |
for (var num in numberList.tns) { | |
console.log('Your number:', formatNumber(num)); | |
} | |
} | |
}; | |
var configure = function () { | |
if (program.items) { | |
itemsPerPage = program.items; | |
console.log('Overrode items per page to', itemsPerPage); | |
} | |
if (program.username && program.password) { | |
console.log('Overrode username and password.'); | |
flowroute.configuration.username = program.username; | |
flowroute.configuration.password = program.password; | |
} | |
}; | |
program | |
.version('0.0.1') | |
.option('-u, --username <username>', 'Username') | |
.option('-p, --password <password>', 'Password') | |
.option('-i, --items <n>', 'Items per Page'); | |
program | |
.command('listNPAs') | |
.action(function () { | |
configure(); | |
flowroute.PurchasablePhoneNumbersController.listAvailableNPAs(itemsPerPage, listNPAs); | |
}); | |
program | |
.command('listExchanges <areaCode>') | |
.action(function (areaCode) { | |
configure(); | |
flowroute.PurchasablePhoneNumbersController.listAreaAndExchange( | |
itemsPerPage, | |
areaCode, | |
1, | |
listAreaAndExchange); | |
}); | |
program | |
.command('listNumbers <areaCode> <exchange>') | |
.action(function (areaCode, exchange) { | |
configure(); | |
flowroute.PurchasablePhoneNumbersController.search( | |
itemsPerPage, | |
areaCode, | |
exchange, | |
1, | |
null, | |
null, | |
null, | |
searchNumbers | |
); | |
}); | |
program | |
.command('listMyNumbers') | |
.action(function () { | |
configure(); | |
flowroute.TelephoneNumbersController.listAccountTelephoneNumbers( | |
itemsPerPage, | |
1, | |
null, | |
listMyNumbers); | |
}) | |
program.parse(process.argv); | |
})(require('commander'), require('./lib')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment