minor cleanup
This commit is contained in:
parent
ff8c41b994
commit
4b8a7d2e00
|
@ -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
|
||||
});
|
||||
```
|
||||
|
||||
|
|
25
lib/index.js
25
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++
|
||||
) {
|
||||
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');
|
||||
} else {
|
||||
// Status="OK"
|
||||
return result['ApiResponse']['CommandResponse'][0];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue