Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/pkgcloud/digitalocean/dns/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* index.js: DigitalOcean DNS client
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

var utile = require('utile'),
urlJoin = require('url-join'),
digitalocean = require('../../client');

var Client = exports.Client = function (options) {
digitalocean.Client.call(this, options);

utile.mixin(this, require('./records.js'));
utile.mixin(this, require('./zones.js'));
};
utile.inherits(Client, digitalocean.Client);

Client.prototype.getUrl = function (options) {
options = options || {};

var root = this.serversUrl
? this.protocol + this.serversUrl
: this.protocol + 'api.digitalocean.com';

return urlJoin(root, typeof options === 'string'
? options
: options.path);
};
59 changes: 59 additions & 0 deletions lib/pkgcloud/digitalocean/dns/client/records.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* records.js: DigitalOcean DNS client records functionality
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

var base = require('../../../core/dns'),
errs = require('errs'),
pkgcloud = require('../../../../../lib/pkgcloud'),
dns = pkgcloud.providers.digitalocean.dns;

exports.getRecords = function (zone, callback) {
var self = this,
id = zone instanceof base.Zone ? zone.id : zone;

return self.request({
path: '/domains/' + id + '/records',
}, function (err, body, res) {
return err
? callback(err)
: callback(null, body.records.map(function (record) {
return new dns.Record(self, record);
}));
});
};

exports.getRecord = function (zone, record, callback) {
var self = this,
zoneId = zone instanceof base.Zone ? zone.id : zone,
recordId = record instanceof base.Record ? record.id : record;

return self.request({
path: '/domains/' + zoneId + '/records/' + recordId
}, function (err, body, res) {
return err
? callback(err)
: callback(null, new dns.Record(self, body.record));
});
};

exports.updateRecord = function (zone, record, callback) {
};

exports.updateRecords = function (zone, records, callback) {
};

exports.createRecord = function (zone, record, callback) {
};

exports.createRecords = function (zone, records, callback) {
};

exports.deleteRecord = function (zone, record, callback) {
};

exports.deleteRecords = function (zone, record, callback) {
};
48 changes: 48 additions & 0 deletions lib/pkgcloud/digitalocean/dns/client/zones.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* zones.js: DigitalOcean DNS client zone functionality
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

var base = require('../../../core/dns'),
pkgcloud = require('../../../../../lib/pkgcloud'),
errs = require('errs'),
dns = pkgcloud.providers.digitalocean.dns;

exports.getZones = function (callback) {
var self = this;
return self.request({
path: '/domains'
}, function (err, body, res) {
return err
? callback(err)
: callback(null, body.domains.map(function (domain) {
return new dns.Zone(self, domain);
}));
});
};

exports.getZone = function (zone, callback) {
var id = zone instanceof dns.Zone ? zone.id : zone;
return this.request({
path: '/domains/' + id
}, function (err, body, res) {
return err
? callback(err)
: callback(null, new dns.Zone(self, body.domain));
});
};

exports.createZone = function (options, callback) {
};

exports.exportZone = function (zone, callback) {
};

exports.updateZone = function (zone, callback) {
};

exports.deleteZone = function (zone, options, callback) {
};
15 changes: 15 additions & 0 deletions lib/pkgcloud/digitalocean/dns/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* index.js: Top-level include for the DigitalOcean service
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

exports.Client = require('./client').Client;
exports.Record = require('./record').Record;
exports.Zone = require('./zone').Zone;

exports.createClient = function (options) {
return new exports.Client(options);
};
31 changes: 31 additions & 0 deletions lib/pkgcloud/digitalocean/dns/record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* record.js: DigitalOcean Cloud DNS Record
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

var util = require('utile'),
base = require('../../core/dns/record');

var Record = exports.Record = function Record(zone, details) {
base.Record.call(this, zone, details);
};
util.inherits(Record, base.Record);

Record.prototype._setProperties = function (details) {
this.id = details.id;
this.name = details.name;
this.type = details.record_type;
this.data = details.data;
};

Record.prototype.toJSON = function () {
return {
id: this.id,
name: this.name,
type: this.type,
data: this.data
};
};
29 changes: 29 additions & 0 deletions lib/pkgcloud/digitalocean/dns/zone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* zone.js: DigitalOcean DNS Zone
*
* (C) 2014 Maciej Małecki
* MIT LICENSE
*
*/

var util = require('util'),
base = require('../../core/dns/zone');

var Zone = exports.Zone = function Zone(client, details) {
base.Zone.call(this, client, details);
};
util.inherits(Zone, base.Zone);

Zone.prototype._setProperties = function (details) {
this.id = details.id;
this.name = details.name;
this.ttl = details.ttl;
};

Zone.prototype.toJSON = function () {
return {
id: this.id,
name: this.name,
ttl: this.ttl
};
};
1 change: 1 addition & 0 deletions lib/pkgcloud/digitalocean/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

exports.compute = require('./compute');
exports.dns = require('./dns');