Browse Source

Initial commit

* Added domains API
master
Muthu Kumar 7 years ago
commit
e6eecf24cc
  1. 3
      .gitignore
  2. 27
      index.js
  3. 9
      lib/domains/createDomain.js
  4. 9
      lib/domains/deleteDomain.js
  5. 6
      lib/domains/listDomains.js
  6. 6
      lib/domains/retrieveDomain.js
  7. 27
      package.json

3
.gitignore

@ -0,0 +1,3 @@
node_modules
config.js
samples.js

27
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;

9
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;

9
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;

6
lib/domains/listDomains.js

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

6
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;

27
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"
}
}
Loading…
Cancel
Save