digital ocean API

This commit is contained in:
William Mantly 2016-05-23 18:25:38 -04:00
parent 15cac181c3
commit 32e70d4be4

View File

@ -1,19 +1,16 @@
var request = require('request'); var request = require('request');
api = function(key){ api = function(key){
key = key || require('./secrets.js').doAPI; key = key || require('./secrets.js').doAPI;
this.BASEURL = 'https://api.digitalocean.com/v2/'; this.BASEURL = 'https://api.digitalocean.com/v2/';
this.headers = { this.headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer '+key 'Authorization': 'Bearer '+key
} }
// API mathods
this.account = function(callback){ this.account = function(callback){
var options = { var options = {
url: this.BASEURL+"account", url: this.BASEURL+'account',
headers: this.headers headers: this.headers
}; };
@ -38,7 +35,7 @@ api = function(key){
resources: [ resources: [
{ {
resource_id: dropletID, resource_id: dropletID,
resource_type: "droplet" resource_type: 'droplet'
} }
] ]
}; };
@ -56,9 +53,9 @@ api = function(key){
this.dropletCreate = function(args, callback){ this.dropletCreate = function(args, callback){
var data = { var data = {
name: args.name, // || return false, name: args.name, // || return false,
region: args.region || "nyc3", region: args.region || 'nyc3',
size: args.size || "512mb", size: args.size || '512mb',
image: args.image || "ubuntu-14-04-x64", image: args.image || 'ubuntu-14-04-x64',
ssh_keys: args.ssh_key || null, ssh_keys: args.ssh_key || null,
backups: args.backup || false, backups: args.backup || false,
private_networking: args.private_networking || true, private_networking: args.private_networking || true,
@ -77,7 +74,7 @@ api = function(key){
this.dropletDestroy = function(dropletID, callback){ this.dropletDestroy = function(dropletID, callback){
var options = { var options = {
url: this.BASEURL+"droplets/"+dropletID, url: this.BASEURL+'droplets/'+dropletID,
headers: this.headers headers: this.headers
}; };
@ -88,7 +85,7 @@ api = function(key){
this.dropletInfo = function(dropletID, callback){ this.dropletInfo = function(dropletID, callback){
var options = { var options = {
url: this.BASEURL+"droplets/"+dropletID, url: this.BASEURL+'droplets/'+dropletID,
headers: this.headers headers: this.headers
}; };