-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital-ocean.js
52 lines (39 loc) · 1.25 KB
/
digital-ocean.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var q = require('q');
var rest = require('restler');
var digitalOcean = function (apiKey) {
var url = 'https://api.digitalocean.com/v2/';
var options = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey
}
};
this.getDomains = function () {
var deferred = q.defer();
rest.get(url + 'domains', options).on('complete', function (data) {
deferred.resolve(data);
});
return deferred.promise;
};
this.updateDomainRecord = function (domain, recordName, recordId, data) {
var deferred = q.defer();
rest.putJson(url + 'domains/' + domain + '/records/' + recordId, {'name': recordName, 'data': data}, options).on('complete', function (data) {
deferred.resolve(data);
});
return deferred.promise;
};
this.getDomainRecord = function (domain, recordName) {
var deferred = q.defer();
rest.get(url + 'domains/' + domain + '/records', options).on('complete', function (data) {
var i;
var domainRecords = data.domain_records;
for (i in domainRecords) {
if (domainRecords[i].name === recordName) {
deferred.resolve(domainRecords[i]);
}
}
});
return deferred.promise;
};
};
module.exports = digitalOcean;