namecheap api integration fixes
This commit is contained in:
parent
8a90e2017d
commit
366fd523ae
49
lib/index.js
49
lib/index.js
|
@ -59,7 +59,7 @@ module.exports.create = function (config) {
|
||||||
url: url,
|
url: url,
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
var responseBody = response.body;
|
var responseBody = response.body;
|
||||||
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'] === 'ERROR') {
|
||||||
|
@ -84,7 +84,6 @@ module.exports.create = function (config) {
|
||||||
return api('namecheap.domains.getList',{}).then(function (zonesResponse) {
|
return api('namecheap.domains.getList',{}).then(function (zonesResponse) {
|
||||||
// console.log('zones');
|
// console.log('zones');
|
||||||
// console.log(zonesResponse);
|
// console.log(zonesResponse);
|
||||||
|
|
||||||
return zonesResponse['DomainGetListResult'].map(function (x) {
|
return zonesResponse['DomainGetListResult'].map(function (x) {
|
||||||
return x['Domain'][0]['$']['Name'];
|
return x['Domain'][0]['$']['Name'];
|
||||||
});
|
});
|
||||||
|
@ -103,18 +102,36 @@ module.exports.create = function (config) {
|
||||||
// the rest of the components are the TLD
|
// the rest of the components are the TLD
|
||||||
params['TLD'] = zone.split('.').splice(1).join('.');
|
params['TLD'] = zone.split('.').splice(1).join('.');
|
||||||
|
|
||||||
params['HostName1'] = ch.dnsPrefix;
|
// setting a host record overwrites all existing,
|
||||||
params['RecordType1'] = 'TXT';
|
// adding a new records means you've have to send back all previous records too
|
||||||
params['Address1'] = txt;
|
|
||||||
params['TTL1'] = 1; // in minutes
|
|
||||||
|
|
||||||
return api('namecheap.domains.dns.setHosts',params).then(function (setHostResponse) {
|
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
|
||||||
// console.log('setHost');
|
var currentHostRecordsCount = hostsResponse['DomainDNSGetHostsResult'][0]['host'].length;
|
||||||
// console.log(setHostResponse);
|
|
||||||
return true
|
|
||||||
|
|
||||||
}).catch(function (err) {
|
for (var i = 0; i < currentHostRecordsCount; i++) {
|
||||||
throw new Error('record did not set. check subdomain, api key, etc');
|
// console.log(hostsResponse['DomainDNSGetHostsResult'][i]['host'][0]);
|
||||||
|
var currentEntry = hostsResponse['DomainDNSGetHostsResult'][0]['host'][i]['$'];
|
||||||
|
|
||||||
|
params['HostName'+(i+1)] = currentEntry['Name'];
|
||||||
|
params['RecordType'+(i+1)] = currentEntry['Type'];
|
||||||
|
params['Address'+(i+1)] = currentEntry['Address'];
|
||||||
|
params['TTL'+(i+1)] = currentEntry['TTL'];
|
||||||
|
}
|
||||||
|
|
||||||
|
params['HostName'+(currentHostRecordsCount+1)] = ch.dnsPrefix;
|
||||||
|
params['RecordType'+(currentHostRecordsCount+1)] = 'TXT';
|
||||||
|
params['Address'+(currentHostRecordsCount+1)] = txt;
|
||||||
|
params['TTL'+(currentHostRecordsCount+1)] = 100; // in minutes
|
||||||
|
|
||||||
|
// console.log(params);
|
||||||
|
|
||||||
|
return api('namecheap.domains.dns.setHosts',params).then(function (setHostResponse) {
|
||||||
|
// console.log('setHost');
|
||||||
|
// console.log(setHostResponse);
|
||||||
|
return true
|
||||||
|
}).catch(function (err) {
|
||||||
|
throw new Error('record did not set. check subdomain, api key, etc');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -137,11 +154,11 @@ module.exports.create = function (config) {
|
||||||
params['TLD'] = zone.split('.').splice(1).join('.');
|
params['TLD'] = zone.split('.').splice(1).join('.');
|
||||||
|
|
||||||
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
|
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
|
||||||
console.log('hosts');
|
// console.log('hosts');
|
||||||
console.log(hostsResponse);
|
// console.log(hostsResponse);
|
||||||
|
var currentHostRecords = hostsResponse['DomainDNSGetHostsResult'][0]['host'];
|
||||||
var entries = hostsResponse['DomainDNSGetHostsResult'].filter(function (x) {
|
|
||||||
|
|
||||||
|
var entries = currentHostRecords.filter(function (x) {
|
||||||
return x['$']['Type'] === 'TXT';
|
return x['$']['Type'] === 'TXT';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue