From 1738688fe1bbb103c69f07cc9d8e1c5cbde659ab Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Sun, 11 Feb 2018 13:26:00 +0530 Subject: [PATCH] Added domain.Records API. Up to 0.2.0 --- .eslintrc.js | 36 ++++++++++++++++++++++++++++++++++++ index.js | 33 +++++++++++++++++++++++---------- lib/domain-records/create.js | 6 ++++++ lib/domain-records/delete.js | 6 ++++++ lib/domain-records/list.js | 6 ++++++ lib/domain-records/retrieve.js | 6 ++++++ lib/domain-records/update.js | 6 ++++++ lib/domains/create.js | 9 +++++++++ lib/domains/createDomain.js | 9 --------- lib/domains/delete.js | 6 ++++++ lib/domains/deleteDomain.js | 9 --------- lib/domains/list.js | 6 ++++++ lib/domains/listDomains.js | 6 ------ lib/domains/retrieve.js | 6 ++++++ lib/domains/retrieveDomain.js | 6 ------ package.json | 2 +- 16 files changed, 117 insertions(+), 41 deletions(-) create mode 100644 .eslintrc.js create mode 100644 lib/domain-records/create.js create mode 100644 lib/domain-records/delete.js create mode 100644 lib/domain-records/list.js create mode 100644 lib/domain-records/retrieve.js create mode 100644 lib/domain-records/update.js create mode 100644 lib/domains/create.js delete mode 100644 lib/domains/createDomain.js create mode 100644 lib/domains/delete.js delete mode 100644 lib/domains/deleteDomain.js create mode 100644 lib/domains/list.js delete mode 100644 lib/domains/listDomains.js create mode 100644 lib/domains/retrieve.js delete mode 100644 lib/domains/retrieveDomain.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..338c737 --- /dev/null +++ b/.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 + }] + } +}; \ No newline at end of file diff --git a/index.js b/index.js index 0ef5640..3b82036 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,19 @@ const axios = require('axios'); +const path = require('path'); const { token -} = require('./config') +} = require(path.resolve(path.dirname(require.main.filename), 'config')); const domainList = require('./lib/domains/list'); const domainCreate = require('./lib/domains/create'); 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({ baseURL: 'https://api.digitalocean.com/v2', @@ -17,11 +23,18 @@ const instance = axios.create({ } }); -const domain = { - List: (instance) => domainList(instance), - Create: (instance, domainObject) => domainCreate(instance, domainObject), - Retrieve: (instance, domainName) => domainRetrieve(instance, domainName), - Delete: (instance, domainName) => domainDelete(instance, domainName), -}; - -module.exports.domain = domain; \ No newline at end of file +module.exports = { + domain: { + List: () => domainList(instance), + Create: (domainObject) => domainCreate(instance, domainObject), + 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), + } + } +}; \ No newline at end of file diff --git a/lib/domain-records/create.js b/lib/domain-records/create.js new file mode 100644 index 0000000..4a0e8e6 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domain-records/delete.js b/lib/domain-records/delete.js new file mode 100644 index 0000000..844f4fe --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domain-records/list.js b/lib/domain-records/list.js new file mode 100644 index 0000000..be94f29 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domain-records/retrieve.js b/lib/domain-records/retrieve.js new file mode 100644 index 0000000..b4ca73b --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domain-records/update.js b/lib/domain-records/update.js new file mode 100644 index 0000000..c28b63c --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domains/create.js b/lib/domains/create.js new file mode 100644 index 0000000..605bd8b --- /dev/null +++ b/lib/domains/create.js @@ -0,0 +1,9 @@ +const Create = async (instance, domainObject) => { + res = await instance.post('/domains', { + "name": domainObject.name, + "ip_address": domainObject.ip, + }); + return (res.data); +}; + +module.exports = Create; \ No newline at end of file diff --git a/lib/domains/createDomain.js b/lib/domains/createDomain.js deleted file mode 100644 index 605bd8b..0000000 --- a/lib/domains/createDomain.js +++ /dev/null @@ -1,9 +0,0 @@ -const Create = async (instance, domainObject) => { - res = await instance.post('/domains', { - "name": domainObject.name, - "ip_address": domainObject.ip, - }); - return (res.data); -}; - -module.exports = Create; \ No newline at end of file diff --git a/lib/domains/delete.js b/lib/domains/delete.js new file mode 100644 index 0000000..4693957 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domains/deleteDomain.js b/lib/domains/deleteDomain.js deleted file mode 100644 index 6c1ba8b..0000000 --- a/lib/domains/deleteDomain.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/lib/domains/list.js b/lib/domains/list.js new file mode 100644 index 0000000..d064417 --- /dev/null +++ b/lib/domains/list.js @@ -0,0 +1,6 @@ +const List = async (instance) => { + res = await instance.get(`/domains`); + return(res.data); +}; + +module.exports = List; \ No newline at end of file diff --git a/lib/domains/listDomains.js b/lib/domains/listDomains.js deleted file mode 100644 index d064417..0000000 --- a/lib/domains/listDomains.js +++ /dev/null @@ -1,6 +0,0 @@ -const List = async (instance) => { - res = await instance.get(`/domains`); - return(res.data); -}; - -module.exports = List; \ No newline at end of file diff --git a/lib/domains/retrieve.js b/lib/domains/retrieve.js new file mode 100644 index 0000000..d957c60 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/lib/domains/retrieveDomain.js b/lib/domains/retrieveDomain.js deleted file mode 100644 index 8fed04f..0000000 --- a/lib/domains/retrieveDomain.js +++ /dev/null @@ -1,6 +0,0 @@ -const Delete = async (instance, domainName) => { - res = await instance.post(`/domains/${domainName}`); - return (res.data); -}; - -module.exports = Delete; \ No newline at end of file diff --git a/package.json b/package.json index af123f2..b630de8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "do-node", - "version": "0.1.0", + "version": "0.2.0", "description": "A (partial) DigitalOcean wrapper for Node.", "main": "index.js", "scripts": {