Dynect API connector for node.js.
the node.js Dynect module provides a simple interface for making synchronous (by design and specification) calls to the Dynect API.
although API calls are synchronous, this is facilitated using an asynchronous queue so calls are still non-blocking.
it is a work in progress and further functionality and examples will be provided soon.
contributions are welcome of course.
example 1 :
add A record www.example.com (address '123.45.67.89')
var Dynect = require('dynect');
var dynect = new Dynect('customername', 'username', 'password');
dynect.on('connected', function () {
var zone = 'example.com';
dynect.addRecord('A', zone, 'www.example.com', {
address: '123.45.67.89'
}, 300, function (addResponse) {
console.log(addResponse);
});
dynect.publishZone(zone, function (publishResponse) {
console.log(publishResponse);
});
dynect.disconnect();
});
dynect.connect();
example 2 :
add CNAME record www.example.com (cname 'example.mydomain.com')
var Dynect = require('dynect');
var dynect = new Dynect('customername', 'username', 'password', 300000);
dynect.on('connected', function () {
var zone = 'example.com';
dynect.addRecord('CNAME', zone, 'www.example.com', {
cname: 'example.mydomain.com'
}, 0, function (addResponse) {
console.log(addResponse);
});
dynect.publishZone(zone, function (publishResponse) {
console.log(publishResponse);
});
});
dynect.connect();
example 3 (advanced) :
get all SRV records for '_sip._tcp.example.com' and remove any record with matching target 'voip.mydomain.com'
var Dynect = require('dynect');
var dynect = new Dynect('customername', 'username', 'password');
var zone = 'example.com';
var fqdn = '_sip._tcp.example.com';
var srvTarget = 'voip.mydomain.com';
var ports = [5060, 5070];
dynect.on('connected', function () {
addSrvRecords(zone, fqdn, srvTarget, ports, function () {
dynect.publishZone(zone, function () {
if (callback) {
callback();
}
});
dynect.disconnect();
});
})
dynect.connect();
function addSrvRecords(zone, fqdn, srvTarget, ports, callback) {
dynect.getRecordSet('SRV', zone, fqdn, function (response) {
if (ports !== null && response.status === 'failure' && response.msgs[0].ERR_CD === 'NOT_FOUND') {
newSrvRecords(zone, fqdn, srvTarget, ports, callback);
}
else {
for (var i = 0; i < response.data.length; i++) {
var uri = response.data[i];
var parts = uri.split('/');
var recordId = parts[parts.length - 1];
dynect.getRecord('SRV', zone, fqdn, recordId, function (response) {
if (response.data.rdata.target === srvTarget + '.') {
dynect.removeRecord('SRV', zone, fqdn, recordId);
}
});
}
if (ports !== null) {
newSrvRecords(zone, fqdn, srvTarget, ports, callback);
}
else {
callback();
}
}
});
}
function newSrvRecords(zone, fqdn, srvTarget, ports, callback) {
for (var i = 0; i < ports.length; i++) {
dynect.addRecord('SRV', zone, fqdn, {
port: ports[i],
priority: 10,
target: srvTarget,
weight: 1
}, 60);
}
callback();
}
installation
npm install dynect
enjoy