dropbox-datastore-node
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "dropbox-datastore-node", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Node.js wrapper for Dropbox Datastore API", | ||
@@ -5,0 +5,0 @@ "main": "src/dropbox-datastore-node.js", |
@@ -5,3 +5,2 @@ #Node.js wrapper for Dropbox Datastore API | ||
Just a bunch of sample options, the full documentation will come. | ||
``` | ||
@@ -32,4 +31,20 @@ var DropboxDatastore = require('../src/dropbox-datastore-node'); | ||
###Testing | ||
The test need the config file which contains the app key and secret. | ||
For easy testing I also included an access token which is used for testing. | ||
``` | ||
exports.options = { | ||
app_key: '...', | ||
app_secret: '...', | ||
response_type: 'code', | ||
redirect_uri: 'http://localhost:3000/' // The / is the path and is required | ||
}; | ||
exports.test_token = 'y-8E3SDJgGMAAAAAAAAAAdOLY39769xtn9AUbLA1-jtwhEHGv2jHXs2m5X6FgddI'; // Test token | ||
``` | ||
###TODO | ||
Implementing all the endpoint of the current API | ||
Simplyfying the put_delta endpoint to make CRUD operations easier |
@@ -1,4 +0,9 @@ | ||
/* | ||
/** | ||
* Dropbox datastore API for Node.js | ||
* | ||
* Node.js wrapper for Dropbox datastore API | ||
* | ||
* @author Daniele Piccone mail@danielepiccone.com | ||
* @version 0.0.1 | ||
* @license MIT | ||
*/ | ||
@@ -9,2 +14,11 @@ | ||
/** | ||
* Build the datastore client | ||
* | ||
* Usage: | ||
* var datastore = new DropboxDatastore(options); | ||
* | ||
* @param {object} Options an object with all the options | ||
*/ | ||
function DropboxDatastore(options){ | ||
@@ -27,2 +41,3 @@ this.app_key = options.app_key; | ||
/* | ||
DropboxDatastore.prototype.authorize = function() { | ||
@@ -39,3 +54,11 @@ console.log('authorizing'); | ||
}; | ||
*/ | ||
/** | ||
* Get the access token for accessing the API | ||
* | ||
* @param {string} bearer the bearer token received from the oAuth dialog | ||
* @param {function} fn the callback to execute with the received data fn(data) | ||
*/ | ||
DropboxDatastore.prototype.getToken = function(bearer,fn) { | ||
@@ -70,2 +93,8 @@ console.log('getting token'); | ||
/** | ||
* Get the information about a Dropbox Account | ||
* | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.getInfo = function(fn) { | ||
@@ -87,2 +116,8 @@ console.log('getting info'); | ||
/** | ||
* List datastores for the current user | ||
* | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.listDatastores = function(fn) { | ||
@@ -104,2 +139,31 @@ console.log('listing datastores'); | ||
/** | ||
* Check the datastore ID and return revision and handle | ||
* | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.getDatastore = function(dsid,fn) { | ||
console.log('getting datastores'); | ||
var self = this; | ||
var req = https.request({ | ||
method: 'GET', | ||
host: 'api.dropbox.com', | ||
path: '/1/datastores/get_datastore?dsid='+dsid, | ||
headers: { | ||
'Authorization': 'Bearer ' + self._token | ||
} | ||
},function(res){ | ||
self.callback(res,fn); | ||
}); | ||
req.end(); | ||
}; | ||
/** | ||
* Create a new datastore | ||
* | ||
* @param {string} datastore the name of the datastore | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.getCreateDatastore = function(datastore,fn) { | ||
@@ -127,2 +191,9 @@ console.log('creating/getting datastore ' + datastore); | ||
/** | ||
* Retrieve a snapshot of the datastore | ||
* | ||
* @param {string} handle_id the handle of the datastore | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.retrieveSnapshot = function(h,fn) { | ||
@@ -150,2 +221,10 @@ console.log('creating/getting snapshot of ' + h); | ||
/** | ||
* Alter the datastore state | ||
* | ||
* @param {string} handle_id the name of the datastore | ||
* @param {string} change_string the serialized object which describes the change | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.putDelta = function(handle_id,change_string,fn) { | ||
@@ -176,2 +255,32 @@ console.log('creating new record'); | ||
/** | ||
* Check the datastore ID and return revision and handle | ||
* | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.getDeltas = function(handle_id,rev,fn) { | ||
console.log('getting deltas'); | ||
var self = this; | ||
var req = https.request({ | ||
method: 'GET', | ||
host: 'api.dropbox.com', | ||
path: '/1/datastores/get_deltas?handle='+handle_id+'&rev='+rev, | ||
headers: { | ||
'Authorization': 'Bearer ' + self._token | ||
} | ||
},function(res){ | ||
self.callback(res,fn); | ||
}); | ||
req.end(); | ||
}; | ||
/** | ||
* Delete a datastore | ||
* | ||
* @param {string} handle_id the name of the datastore | ||
* @param {function} fn callback function(data) | ||
*/ | ||
DropboxDatastore.prototype.deleteDatastore = function(handle_id,fn) { | ||
@@ -178,0 +287,0 @@ console.log('deleting datastore ' + handle_id); |
var assert = require("assert"); | ||
var config = require("./config"); | ||
var DropboxDatastore = require('../src/dropbox-datastore-node'); | ||
global._token = 'y-8E3SDJgGMAAAAAAAAAAdOLY36768xtn9AUbLA1-jtwhEFGv2jHXs2m5X5FgdoI'; // Test token | ||
global._token = config.test_token; | ||
describe('DropboxDatastoreTest', function(){ | ||
var options = { | ||
app_key: 'skt9hjvq37sid0x', | ||
app_secret: '5accd160dez5959', | ||
response_type: 'code', | ||
redirect_uri: 'http://localhost:3000/' // The / is the path and is required | ||
}; | ||
var options = config.options | ||
var datastore = new DropboxDatastore(options); | ||
@@ -19,4 +15,7 @@ | ||
/* | ||
* Get a bearer token first | ||
* | ||
it('should authorize with token', function(done){ | ||
datastore.getToken('jrL3ybkwhPcAAAAAAAAAAfq6r3tipgcnO9KXuGIb-BI',function(auth){ | ||
datastore.getToken(bearer_token,function(auth){ | ||
if (!!datastore._token) { | ||
@@ -30,4 +29,4 @@ console.log('got token: ' + datastore._token); | ||
}); | ||
*/ | ||
it('should call the info api', function(done){ | ||
@@ -57,2 +56,3 @@ datastore._token = global._token; | ||
it('should create datastore', function(done){ | ||
@@ -71,2 +71,13 @@ datastore._token = global._token; | ||
it('should get datastores', function(done){ | ||
datastore._token = global._token; | ||
datastore.getDatastore('test',function(data) { | ||
if (!!data.handle) { | ||
done(); | ||
} else { | ||
throw new Error('No data received'); | ||
} | ||
}); | ||
}); | ||
it('should retrieve a snapshot', function(done){ | ||
@@ -87,3 +98,3 @@ datastore._token = global._token; | ||
datastore.putDelta(global._handle,changes,function(data) { | ||
console.log(data); | ||
//console.log(data); | ||
if (!!data) { | ||
@@ -97,2 +108,16 @@ // Assing handle to a temporary | ||
}); | ||
it('should get delta', function(done){ | ||
datastore._token = global._token; | ||
var rev = 0; | ||
datastore.getDeltas(global._handle,rev,function(data) { | ||
//console.log(data); | ||
if (!!data) { | ||
// Assing handle to a temporary | ||
done(); | ||
} else { | ||
throw new Error('No data received'); | ||
} | ||
}); | ||
}); | ||
@@ -103,3 +128,3 @@ it('should remove a datastore', function(done){ | ||
datastore.deleteDatastore(global._handle,function(data) { | ||
console.log(data); | ||
//console.log(data); | ||
if (!!data.ok) { | ||
@@ -106,0 +131,0 @@ done(); |
13866
5
405
49