Comparing version 0.0.1 to 0.0.2
235
index.js
@@ -9,28 +9,16 @@ /*globals require,module */ | ||
var util = require("util"); | ||
var dutil = require("./util"); | ||
//our utils | ||
var HttpOptionCreator = dutil.HttpOptionCreator; | ||
var toJSON = dutil.toJSON; | ||
var objToHttpGetParam = dutil.objToHttpGetParam; | ||
/** | ||
* augments the request option with the baseOption | ||
* | ||
*/ | ||
var HttpOptionCreator = function(baseOption) { | ||
return function(requestOption) { | ||
return util._extend(baseOption, requestOption); | ||
} | ||
} | ||
var toJSON = function(buffer) { | ||
return JSON.parse(buffer.toString('utf-8')); | ||
}; | ||
var createPromise = function(params,towrite) { | ||
console.log(params); | ||
return new Promise(function (resolve, reject) { | ||
var req = https.request(params,function(res) { | ||
res.setEncoding('utf8'); | ||
var buffer = ""; | ||
//204 is successful delete request | ||
if ( res.statusCode === 200 || res.statusCode === 204 ) { | ||
//204 is successful delete request,201 is created | ||
if ( res.statusCode === 200 || res.statusCode === 204 || res.statusCode === 201 ) { | ||
res.on('data', function (chunk) { | ||
@@ -47,3 +35,7 @@ buffer += chunk; | ||
res.on('end',function() { | ||
resolve(toJSON(buffer)); | ||
if ( buffer ) { | ||
resolve(toJSON(buffer)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
@@ -65,12 +57,20 @@ }); | ||
/** | ||
* Domain | ||
* | ||
* @param DropKit | ||
* @returns {domain} | ||
*/ | ||
var domain = function(DropKit) { | ||
this.dropkit = DropKit; | ||
return this; | ||
}; | ||
domain.prototype.create = function(name,ipaddress) { | ||
var tosubmit = { | ||
name : name, | ||
ip_address : ipaddress | ||
"name" : name, | ||
"ip_address" : ipaddress | ||
}; | ||
@@ -86,2 +86,92 @@ | ||
/** | ||
* https://developers.digitalocean.com/#domain-records | ||
* | ||
* | ||
* @param domainName | ||
* @param DropKit | ||
*/ | ||
var record = function(domainName,DropKit) { | ||
this.name = domainName; | ||
this.dropkit = DropKit; | ||
}; | ||
/** | ||
* | ||
* https://developers.digitalocean.com/#create-a-new-domain-record | ||
* | ||
* @param recordData | ||
*/ | ||
record.prototype.create = function(recordData) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/domains/' + this.name + '/records'}),JSON.stringify(recordData)); | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#update-a-domain-record | ||
* | ||
* @param recordId | ||
* @param newdata | ||
*/ | ||
record.prototype.update = function(recordId,newdata) { | ||
return createPromise(this.dropkit.createOption({ method: 'PUT' , path: '/v2/domains/' + this.name + '/records/' + recordId}),JSON.stringify(newdata)); | ||
}; | ||
/** | ||
* | ||
* https://developers.digitalocean.com/#delete-a-domain-record | ||
* | ||
* @param recordId | ||
*/ | ||
record.prototype.delete = function(recordId) { | ||
return createPromise(this.dropkit.createOption({ method: 'DELETE' , path: '/v2/domains/' + this.name + '/records/' + recordId})); | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#droplets | ||
* | ||
* @param DropKit | ||
* @returns {droplet} | ||
*/ | ||
var droplet = function(DropKit) { | ||
this.dropkit = DropKit; | ||
return this; | ||
}; | ||
droplet.prototype.create = function(droplet) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/droplets'}),JSON.stringify(droplet)); | ||
}; | ||
droplet.prototype.kernels = function(dropletId) { | ||
return createPromise(this.dropkit.createOption({ method: 'GET' , path: '/v2/droplets/' + dropletId + '/kernels'})); | ||
}; | ||
droplet.prototype.snapshots = function(dropletId) { | ||
return createPromise(this.dropkit.createOption({ method: 'GET' , path: '/v2/droplets/' + dropletId + '/snapshots'})); | ||
}; | ||
droplet.prototype.backups = function(dropletId) { | ||
return createPromise(this.dropkit.createOption({ method: 'GET' , path: '/v2/droplets/' + dropletId + '/backups'})); | ||
}; | ||
droplet.prototype.delete = function(dropletId) { | ||
return createPromise(this.dropkit.createOption({ method: 'DELETE' , path: '/v2/droplets/' + dropletId})); | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#droplet-actions | ||
* | ||
* @param dropletId | ||
* @param action | ||
*/ | ||
droplet.prototype.action = function(dropletId,action) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/droplets/' + dropletId}),JSON.stringify({type: action})); | ||
}; | ||
/** | ||
* Main dropkit obj | ||
* | ||
* @param token | ||
* @constructor | ||
*/ | ||
var DropKit = function(token) { | ||
@@ -93,7 +183,9 @@ | ||
headers: { | ||
'Content-Type' : 'application/json', | ||
'Authorization' : 'Bearer ' + token | ||
"Content-Type" : "application/json; charset=utf-8", | ||
"Authorization" : 'Bearer ' + token | ||
} | ||
}; | ||
this.createOption = HttpOptionCreator(baseOption); | ||
}; | ||
@@ -111,3 +203,22 @@ | ||
/** | ||
* https://developers.digitalocean.com/#actions | ||
* | ||
* @param actionId | ||
*/ | ||
DropKit.prototype.actions = function(actionId) { | ||
if ( actionId ) { | ||
if ( typeof actionId === "string" ) { //FIXME we probably should also check for number | ||
return createPromise(this.createOption({method: 'GET', path: '/v2/actions/' + actionId})); | ||
} else { | ||
return createPromise(this.createOption({method: 'GET', path: '/v2/actions?' + objToHttpGetParam(actionId)})); | ||
} | ||
} else { | ||
return createPromise(this.createOption({method: 'GET', path: '/v2/actions'})); | ||
} | ||
}; | ||
/** | ||
* Domains | ||
@@ -118,4 +229,7 @@ * | ||
*/ | ||
DropKit.prototype.domains = function() { | ||
return createPromise(this.createOption({ method: 'GET' , path: '/v2/domains'})); | ||
DropKit.prototype.domains = function(domainName) { | ||
var path = "/v2/domains" + (domainName ? ("/" + domainName) : "" ); | ||
return createPromise(this.createOption({ method: 'GET' , path: path})) | ||
}; | ||
@@ -125,2 +239,19 @@ | ||
/** | ||
* | ||
* https://developers.digitalocean.com/#domain-records | ||
* | ||
* | ||
* @param domainName | ||
* @param recordId | ||
*/ | ||
DropKit.prototype.records = function(domainName,recordId) { | ||
var path = "/v2/domains/" + domainName + "/records" + ( recordId ? ( "/" + recordId) : ""); | ||
return createPromise(this.createOption({method: 'GET', path: path})) | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#retrieve-an-existing-domain | ||
@@ -133,12 +264,46 @@ * https://developers.digitalocean.com/#create-a-new-domain | ||
*/ | ||
DropKit.prototype.domain = function(domainName) { | ||
if ( domainName ) { | ||
return createPromise(this.createOption({ method: 'GET' , path: '/v2/domains/' + domainName})) | ||
} else { | ||
return new domain(this); | ||
} | ||
DropKit.prototype.domain = function() { | ||
return new domain(this); | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#domain-records | ||
* | ||
* @param domainName | ||
* @returns {record} | ||
*/ | ||
DropKit.prototype.record = function(domainName) { | ||
return new record(domainName,this.dropkit); | ||
}; | ||
/** | ||
* https://developers.digitalocean.com/#droplets | ||
* | ||
* @param id | ||
*/ | ||
DropKit.prototype.droplets = function(id) { | ||
var path = '/v2/droplets' + (id ? '/' + id : '') ; | ||
return createPromise(this.createOption({method: 'GET', path: path})) | ||
}; | ||
DropKit.prototype.droplet = function() { | ||
return new droplet(this.dropkit); //FIXME, we should just let this be static | ||
}; | ||
/** | ||
* | ||
* https://developers.digitalocean.com/#list-droplet-upgrades | ||
* | ||
*/ | ||
DropKit.prototype.droplet_upgrades = function() { | ||
return createPromise(this.dropkit.createOption({ method: 'GET' , path: '/v2/droplet_upgrades'})); | ||
}; | ||
DropKit.prototype.keys = function(keyIdOrFingerPrint) { | ||
var path = '/v2/account/keys' + ( keyIdOrFingerPrint ? keyIdOrFingerPrint : '/' + keyIdOrFingerPrint); | ||
return createPromise(this.dropkit.createOption({ method: 'GET' , path: path})); | ||
} | ||
module.exports = DropKit; |
{ | ||
"name": "dropkit", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A DigitalOcean Node.js module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "./node_modules/mocha/bin/mocha" | ||
}, | ||
@@ -14,7 +14,15 @@ "author": "Warren Mira warrenmira@gmail.com", | ||
}, | ||
"keywords" : ["digital ocean", "digitalocean","digitalocean api"], | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "https://github.com/wmira/dropkit.git" | ||
"keywords": [ | ||
"digital ocean", | ||
"digitalocean", | ||
"digitalocean api" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wmira/dropkit.git" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.0.1", | ||
"proxyquire": "^1.1.0" | ||
} | ||
} |
@@ -6,3 +6,3 @@ dropkit | ||
Usage: | ||
# Usage: | ||
@@ -24,4 +24,4 @@ npm install --save dropkit | ||
API: | ||
# API: | ||
```javascript | ||
do.accounts(); | ||
@@ -33,1 +33,7 @@ | ||
do.domain().create({'name' : 'name.com','ip_address' : '127.0.0.1'}); | ||
``` | ||
# Dev | ||
1. npm install | ||
2. npm test |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
10277
7
289
2
36
2
2