minor cleanup

This commit is contained in:
AJ ONeal 2019-07-23 02:12:08 -06:00
parent ff8c41b994
commit 4b8a7d2e00
2 changed files with 15 additions and 16 deletions

View File

@ -20,8 +20,8 @@ var dns01 = require('acme-dns-01-namecheap').create({
apiUser: 'username', apiUser: 'username',
apiKey: 'xxxx', apiKey: 'xxxx',
clientIp: 'public ip', clientIp: 'public ip',
username: 'api user', username: 'username',
baseUrl: 'sandbox or production' // default production baseUrl: 'https://api.namecheap.com/xml.response' // default
}); });
``` ```

View File

@ -2,11 +2,12 @@
var util = require('util'); var util = require('util');
var request; // = require('@root/request'); var request; // = require('@root/request');
//var querystring = require('querystring');
var parseString = require('xml2js').parseString; var parseString = require('xml2js').parseString;
parseString = util.promisify(parseString); parseString = util.promisify(parseString);
const SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response'; var SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
const PRODUCTION_URL = 'https://api.namecheap.com/xml.response'; var PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
var defaults = { var defaults = {
baseUrl: PRODUCTION_URL baseUrl: PRODUCTION_URL
@ -48,7 +49,7 @@ module.exports.create = function(config) {
apiUser: config.apiUser, apiUser: config.apiUser,
apiKey: config.apiKey, apiKey: config.apiKey,
username: config.username, username: config.username,
ClientIp: config.clientIp clientIp: config.clientIp
}; };
function api(command, params) { function api(command, params) {
@ -66,19 +67,17 @@ module.exports.create = function(config) {
// console.log(responseBody); // console.log(responseBody);
return parseString(responseBody).then(function(result) { return parseString(responseBody).then(function(result) {
// check response status // check response status
if (result['ApiResponse']['$']['Status'] === 'ERROR') { if (result['ApiResponse']['$']['Status'] === 'OK') {
for ( return result['ApiResponse']['CommandResponse'][0];
let i = 0; }
i < result['ApiResponse']['Errors'].length;
i++ // Status="ERROR"
) { var i;
var len = result['ApiResponse']['Errors'].length;
for (i = 0; i < len; i += 1) {
console.log(result['ApiResponse']['Errors'][i]); console.log(result['ApiResponse']['Errors'][i]);
} }
throw new Error('API Error'); throw new Error('API Error');
} else {
// Status="OK"
return result['ApiResponse']['CommandResponse'][0];
}
}); });
}); });
} }