Browse Source

Added domain.Records API. Up to 0.2.0

master
Muthu Kumar 7 years ago
parent
commit
1738688fe1
  1. 36
      .eslintrc.js
  2. 31
      index.js
  3. 6
      lib/domain-records/create.js
  4. 6
      lib/domain-records/delete.js
  5. 6
      lib/domain-records/list.js
  6. 6
      lib/domain-records/retrieve.js
  7. 6
      lib/domain-records/update.js
  8. 0
      lib/domains/create.js
  9. 6
      lib/domains/delete.js
  10. 9
      lib/domains/deleteDomain.js
  11. 0
      lib/domains/list.js
  12. 6
      lib/domains/retrieve.js
  13. 6
      lib/domains/retrieveDomain.js
  14. 2
      package.json

36
.eslintrc.js

@ -0,0 +1,36 @@
module.exports = {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-var": "error",
"prefer-const": ["error", {
"destructuring": "any",
"ignoreReadBeforeAssign": false
}],
"prefer-destructuring": ["error", {
"array": true,
"object": true
}, {
"enforceForRenamedProperties": true
}]
}
};

31
index.js

@ -1,13 +1,19 @@
const axios = require('axios'); const axios = require('axios');
const path = require('path');
const { const {
token token
} = require('./config') } = require(path.resolve(path.dirname(require.main.filename), 'config'));
const domainList = require('./lib/domains/list'); const domainList = require('./lib/domains/list');
const domainCreate = require('./lib/domains/create'); const domainCreate = require('./lib/domains/create');
const domainRetrieve = require('./lib/domains/retrieve'); const domainRetrieve = require('./lib/domains/retrieve');
const domainDelete = require('./lib/domains/deleteDomain'); const domainDelete = require('./lib/domains/delete');
const listDomainRecords = require('./lib/domain-records/list');
const createDomainRecords = require('./lib/domain-records/create');
const retrieveDomainRecords = require('./lib/domain-records/retrieve');
const updateDomainRecords = require('./lib/domain-records/update');
const deleteDomainRecords = require('./lib/domain-records/delete');
const instance = axios.create({ const instance = axios.create({
baseURL: 'https://api.digitalocean.com/v2', baseURL: 'https://api.digitalocean.com/v2',
@ -17,11 +23,18 @@ const instance = axios.create({
} }
}); });
const domain = { module.exports = {
List: (instance) => domainList(instance), domain: {
Create: (instance, domainObject) => domainCreate(instance, domainObject), List: () => domainList(instance),
Retrieve: (instance, domainName) => domainRetrieve(instance, domainName), Create: (domainObject) => domainCreate(instance, domainObject),
Delete: (instance, domainName) => domainDelete(instance, domainName), Retrieve: (domainObject) => domainRetrieve(instance, domainObject),
Delete: (domainObject) => domainDelete(instance, domainObject),
Records: {
List: (domainObject) => listDomainRecords(instance, domainObject),
Create: (domainObject, domainRecords) => createDomainRecords(instance, domainObject, domainRecords),
Retrieve: (domainObject, recordId) => retrieveDomainRecords(instance, domainObject, recordId),
Update: (domainObject, recordId) => updateDomainRecords(instance, domainObject, recordId),
Delete: (domainObject, recordId) => deleteDomainRecords(instance, domainObject, recordId),
}
}
}; };
module.exports.domain = domain;

6
lib/domain-records/create.js

@ -0,0 +1,6 @@
const Create = async (instance, domainObject, domainRecords) => {
res = await instance.post(`/domains/${domainObject.name}/records`, domainRecords);
return (res.data);
};
module.exports = Create;

6
lib/domain-records/delete.js

@ -0,0 +1,6 @@
const Delete = async (instance, domainObject, recordId) => {
res = await instance.delete(`/domains/${domainObject.name}/records/${recordId}`);
return ({status: 'OK'});
};
module.exports = Delete;

6
lib/domain-records/list.js

@ -0,0 +1,6 @@
const Records = async (instance, domainObject) => {
res = await instance.get(`/domains/${domainObject.name}/records`);
return (res.data);
};
module.exports = Records;

6
lib/domain-records/retrieve.js

@ -0,0 +1,6 @@
const Retrieve = async (instance, domainObject, recordId) => {
res = await instance.get(`/domains/${domainObject.name}/records/${recordId}`);
return (res.data);
};
module.exports = Retrieve;

6
lib/domain-records/update.js

@ -0,0 +1,6 @@
const Update = async (instance, domainObject, recordId) => {
res = await instance.put(`/domains/${domainObject.name}/records/${recordId}`);
return (res.data);
};
module.exports = Update;

0
lib/domains/createDomain.js → lib/domains/create.js

6
lib/domains/delete.js

@ -0,0 +1,6 @@
const Delete = async (instance, domainObject) => {
res = await instance.delete(`/domains/${domainObject.name}`);
return ({ status: 'OK' });
};
module.exports = Delete;

9
lib/domains/deleteDomain.js

@ -1,9 +0,0 @@
const Delete = async (instance, domainObject) => {
res = await instance.post(`/domains`, {
"name": domainObject.name,
"ip_address": domainObject.ip,
});
return (res.data);
};
module.exports = Delete;

0
lib/domains/listDomains.js → lib/domains/list.js

6
lib/domains/retrieve.js

@ -0,0 +1,6 @@
const Retrieve = async (instance, domainObject) => {
res = await instance.get(`/domains/${domainObject.name}`);
return (res.data);
};
module.exports = Retrieve;

6
lib/domains/retrieveDomain.js

@ -1,6 +0,0 @@
const Delete = async (instance, domainName) => {
res = await instance.post(`/domains/${domainName}`);
return (res.data);
};
module.exports = Delete;

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "do-node", "name": "do-node",
"version": "0.1.0", "version": "0.2.0",
"description": "A (partial) DigitalOcean wrapper for Node.", "description": "A (partial) DigitalOcean wrapper for Node.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

Loading…
Cancel
Save