From 4b8a7d2e00c66ff9bcbff2f870828ec0ef8a1ab3 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 23 Jul 2019 02:12:08 -0600 Subject: [PATCH] minor cleanup --- README.md | 4 ++-- lib/index.js | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 9c16a44..2c30085 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ var dns01 = require('acme-dns-01-namecheap').create({ apiUser: 'username', apiKey: 'xxxx', clientIp: 'public ip', - username: 'api user', - baseUrl: 'sandbox or production' // default production + username: 'username', + baseUrl: 'https://api.namecheap.com/xml.response' // default }); ``` diff --git a/lib/index.js b/lib/index.js index e8e2770..5cb6c74 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,11 +2,12 @@ var util = require('util'); var request; // = require('@root/request'); +//var querystring = require('querystring'); var parseString = require('xml2js').parseString; parseString = util.promisify(parseString); -const SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response'; -const PRODUCTION_URL = 'https://api.namecheap.com/xml.response'; +var SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response'; +var PRODUCTION_URL = 'https://api.namecheap.com/xml.response'; var defaults = { baseUrl: PRODUCTION_URL @@ -48,7 +49,7 @@ module.exports.create = function(config) { apiUser: config.apiUser, apiKey: config.apiKey, username: config.username, - ClientIp: config.clientIp + clientIp: config.clientIp }; function api(command, params) { @@ -66,19 +67,17 @@ module.exports.create = function(config) { // console.log(responseBody); return parseString(responseBody).then(function(result) { // check response status - if (result['ApiResponse']['$']['Status'] === 'ERROR') { - for ( - let i = 0; - i < result['ApiResponse']['Errors'].length; - i++ - ) { - console.log(result['ApiResponse']['Errors'][i]); - } - throw new Error('API Error'); - } else { - // Status="OK" + if (result['ApiResponse']['$']['Status'] === 'OK') { return result['ApiResponse']['CommandResponse'][0]; } + + // Status="ERROR" + var i; + var len = result['ApiResponse']['Errors'].length; + for (i = 0; i < len; i += 1) { + console.log(result['ApiResponse']['Errors'][i]); + } + throw new Error('API Error'); }); }); }