From 63b7a3b4812f836d737c0f6dca3f4ca490250c44 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 20 May 2016 09:11:31 -0400 Subject: [PATCH] do api started --- doapi.js | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/doapi.js b/doapi.js index 1cc5421..4d2abc6 100644 --- a/doapi.js +++ b/doapi.js @@ -2,50 +2,29 @@ var request = require('request'); api = function(key){ - if(!key){ - key = require('./secrets.js').doAPI; - } - this.url = 'https://digitalocean.com/v2/'; + key = key || require('./secrets.js').doAPI; + this.BASEURL = 'https://api.digitalocean.com/v2/'; + this.headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer '+key } - this.byTag: function(tag, callback){ + this.byTag = function(tag, callback){ var options = { - url: this.url+'droplets?tag_name='+tag, + url: this.BASEURL+'droplets?tag_name='+tag, headers: this.headers } + return request.get(options, function(error, response, body){ return callback(body, response, error); }) }; - this.setTag: function(id, tag, callback){ - return request.post(url+) - }; + // this.setTag = function(id, tag, callback){ + // return request.post(url+) + // }; + return this; } -api = { -} - - - - - - - -var httpOptions = { - url:'http://' + ip + ':15000', - body: JSON.stringify({ - code: req.body.code - }) - }; - - return request.post(httpOptions, function(error, response, body){ - body = JSON.parse(body); - body['ip'] = ip.replace('10.0.', ''); - return res.json(body); - }); - module.exports = api; \ No newline at end of file