Comparing version 0.0.2 to 0.0.3
109
index.js
@@ -6,14 +6,13 @@ /*globals require,module */ | ||
var Promise = require("bluebird"); | ||
var pms = require("bluebird"); | ||
var https = require("https"); | ||
var util = require("util"); | ||
var dutil = require("./util"); | ||
var util = require("./util"); | ||
//our utils | ||
var HttpOptionCreator = dutil.HttpOptionCreator; | ||
var toJSON = dutil.toJSON; | ||
var objToHttpGetParam = dutil.objToHttpGetParam; | ||
var HttpOptionCreator = util.HttpOptionCreator; | ||
var toJSON = util.toJSON; | ||
var objToHttpGetParam = util.objToHttpGetParam; | ||
var createPromise = function(params,towrite) { | ||
console.log(params); | ||
return new Promise(function (resolve, reject) { | ||
return new pms(function (resolve, reject) { | ||
var req = https.request(params,function(res) { | ||
@@ -35,2 +34,3 @@ res.setEncoding('utf8'); | ||
res.on('end',function() { | ||
if ( buffer ) { | ||
@@ -47,9 +47,9 @@ resolve(toJSON(buffer)); | ||
} | ||
req.on('error', function(e) { | ||
reject(e); | ||
}); | ||
//flush it | ||
req.end(); | ||
req.on('error', function(e) { | ||
reject(e); | ||
}); | ||
}); | ||
@@ -67,3 +67,2 @@ }; | ||
this.dropkit = DropKit; | ||
return this; | ||
}; | ||
@@ -73,10 +72,4 @@ | ||
domain.prototype.create = function(name,ipaddress) { | ||
var tosubmit = { | ||
"name" : name, | ||
"ip_address" : ipaddress | ||
}; | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/domains'}),JSON.stringify(tosubmit)); | ||
domain.prototype.create = function(data) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/domains'}),JSON.stringify(data)); | ||
}; | ||
@@ -95,4 +88,3 @@ | ||
*/ | ||
var record = function(domainName,DropKit) { | ||
this.name = domainName; | ||
var record = function(DropKit) { | ||
this.dropkit = DropKit; | ||
@@ -107,4 +99,4 @@ }; | ||
*/ | ||
record.prototype.create = function(recordData) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/domains/' + this.name + '/records'}),JSON.stringify(recordData)); | ||
record.prototype.create = function(domainName,recordData) { | ||
return createPromise(this.dropkit.createOption({ method: 'POST' , path: '/v2/domains/' + domainName + '/records'}),JSON.stringify(recordData)); | ||
}; | ||
@@ -119,4 +111,4 @@ | ||
*/ | ||
record.prototype.update = function(recordId,newdata) { | ||
return createPromise(this.dropkit.createOption({ method: 'PUT' , path: '/v2/domains/' + this.name + '/records/' + recordId}),JSON.stringify(newdata)); | ||
record.prototype.update = function(domainName,recordId,newdata) { | ||
return createPromise(this.dropkit.createOption({ method: 'PUT' , path: '/v2/domains/' + domainName + '/records/' + recordId}),JSON.stringify(newdata)); | ||
@@ -131,4 +123,4 @@ }; | ||
*/ | ||
record.prototype.delete = function(recordId) { | ||
return createPromise(this.dropkit.createOption({ method: 'DELETE' , path: '/v2/domains/' + this.name + '/records/' + recordId})); | ||
record.prototype.delete = function(domainName,recordId) { | ||
return createPromise(this.dropkit.createOption({ method: 'DELETE' , path: '/v2/domains/' + domainName+ '/records/' + recordId})); | ||
@@ -194,3 +186,32 @@ }; | ||
/** | ||
* https://developers.digitalocean.com/#retrieve-an-existing-domain | ||
* https://developers.digitalocean.com/#create-a-new-domain | ||
* | ||
* | ||
* @param domainName | ||
* @returns {domain} | ||
*/ | ||
this.domain = new domain(this); | ||
/** | ||
* https://developers.digitalocean.com/#domain-records | ||
* | ||
* @param domainName | ||
* @returns {record} | ||
*/ | ||
this.record = new record(this); | ||
/** | ||
* | ||
* | ||
* @type {droplet} | ||
*/ | ||
this.droplet = new droplet(this); | ||
}; | ||
@@ -236,3 +257,3 @@ | ||
return createPromise(this.createOption({ method: 'GET' , path: path})) | ||
return createPromise(this.createOption({ method: 'GET' , path: path})); | ||
@@ -252,3 +273,3 @@ }; | ||
var path = "/v2/domains/" + domainName + "/records" + ( recordId ? ( "/" + recordId) : ""); | ||
return createPromise(this.createOption({method: 'GET', path: path})) | ||
return createPromise(this.createOption({method: 'GET', path: path})); | ||
@@ -260,23 +281,3 @@ }; | ||
/** | ||
* https://developers.digitalocean.com/#retrieve-an-existing-domain | ||
* https://developers.digitalocean.com/#create-a-new-domain | ||
* | ||
* | ||
* @param domainName | ||
* @returns {domain} | ||
*/ | ||
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); | ||
}; | ||
@@ -293,5 +294,3 @@ /** | ||
}; | ||
DropKit.prototype.droplet = function() { | ||
return new droplet(this.dropkit); //FIXME, we should just let this be static | ||
}; | ||
/** | ||
@@ -312,4 +311,4 @@ * | ||
} | ||
}; | ||
module.exports = DropKit; |
{ | ||
"name": "dropkit", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A DigitalOcean Node.js module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,4 @@ dropkit | ||
[![Build Status](https://travis-ci.org/wmira/dropkit.svg?branch=master)](https://travis-ci.org/wmira/dropkit) | ||
# Usage: | ||
@@ -12,8 +14,8 @@ | ||
```javascript | ||
var dropkit = require("dropkit"); | ||
var do = new dropkit("TOKEN"); | ||
var Dropkit = require("dropkit"); | ||
var dkit = new Dropkit("TOKEN"); | ||
//DropKit uses BlueBird and returns promises instead of callbacks. | ||
do.accounts().then(function(account) { | ||
dkit.accounts().then(function(account) { | ||
console.log(account); | ||
@@ -27,8 +29,7 @@ }).error(function(error) { | ||
```javascript | ||
do.accounts(); | ||
dkit.accounts(); | ||
do.domains(); | ||
do.domain(domainName); | ||
do.domain().delete(domainName); | ||
do.domain().create({'name' : 'name.com','ip_address' : '127.0.0.1'}); | ||
dkit.domains(); | ||
dkit.domain.delete(domainName); | ||
dkit.domain.create({'name' : 'name.com','ip_address' : '127.0.0.1'}); | ||
``` | ||
@@ -35,0 +36,0 @@ |
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
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
8
37
1
10157
280