commit e6eecf24cc77f94eaba08b4832bb3e3a6e15654f Author: Muthu Kumar Date: Sat Feb 10 19:23:31 2018 +0530 Initial commit * Added domains API diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7aa84b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +config.js +samples.js \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..0ef5640 --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +const axios = require('axios'); + +const { + token +} = require('./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 instance = axios.create({ + baseURL: 'https://api.digitalocean.com/v2', + timeout: 10000, + headers: { + 'Authorization': `Bearer ${token}` + } +}); + +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 diff --git a/lib/domains/createDomain.js b/lib/domains/createDomain.js new file mode 100644 index 0000000..605bd8b --- /dev/null +++ b/lib/domains/createDomain.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/deleteDomain.js b/lib/domains/deleteDomain.js new file mode 100644 index 0000000..6c1ba8b --- /dev/null +++ b/lib/domains/deleteDomain.js @@ -0,0 +1,9 @@ +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/listDomains.js b/lib/domains/listDomains.js new file mode 100644 index 0000000..d064417 --- /dev/null +++ b/lib/domains/listDomains.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/retrieveDomain.js b/lib/domains/retrieveDomain.js new file mode 100644 index 0000000..8fed04f --- /dev/null +++ b/lib/domains/retrieveDomain.js @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000..af123f2 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "do-node", + "version": "0.1.0", + "description": "A (partial) DigitalOcean wrapper for Node.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/codefeathers/do-node.git" + }, + "keywords": [ + "DigitalOcean", + "node", + "javascript" + ], + "author": "Muthu Kumar (https://mkr.pw)", + "license": "MIT", + "bugs": { + "url": "https://github.com/codefeathers/do-node/issues" + }, + "homepage": "https://github.com/codefeathers/do-node#readme", + "dependencies": { + "axios": "^0.17.1" + } +}