Permalink
Browse files

Merge pull request #31 from snakamura/sandbox

Support Dropbox sandbox.
  • Loading branch information...
2 parents 8ee0306 + ace33bb commit 01a6f065f2dad908f5bbed7980db6d110b1fea46 @evnm committed Jun 26, 2012
Showing with 13 additions and 14 deletions.
  1. +13 −14 lib/dropbox-node.js
View
27 lib/dropbox-node.js
@@ -12,11 +12,13 @@ var pathLib = require('path')
// Returns a Dropbox Client, through which API calls can be made.
var DropboxClient = exports.DropboxClient =
- function(consumer_key, consumer_secret, access_token, access_token_secret) {
+ function(consumer_key, consumer_secret, access_token, access_token_secret, options) {
+ options = options || {};
this.consumer_key = consumer_key;
this.consumer_secret = consumer_secret;
this.access_token = access_token || undefined;
this.access_token_secret = access_token_secret || undefined;
+ this.root = options.sandbox ? 'sandbox' : 'dropbox';
}
@@ -133,7 +135,7 @@ DropboxClient.prototype.createAccount = function(email, first_name, last_name
DropboxClient.prototype.getFile = function(path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
else if (!optargs) optargs = {};
- var uri = CONTENT_API_URI + '/files/dropbox/' + escapePath(path) +
+ var uri = CONTENT_API_URI + '/files/' + this.root + '/' + escapePath(path) +
(optargs.rev ? '?rev=' + optargs.rev : '');
return this.get(uri, optargs, optargs.range, cb);
}
@@ -142,7 +144,7 @@ DropboxClient.prototype.getFile = function(path, optargs, cb) {
// Uploads contents of a file specified by file to the remote path
DropboxClient.prototype.putFile = function(file, path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
- var uri = CONTENT_API_URI + '/files_put/dropbox/' + escapePath(path) +
+ var uri = CONTENT_API_URI + '/files_put/' + this.root + '/' + escapePath(path) +
'?' + stringifyParams(optargs);
var self = this;
fs.readFile(file, function(err, data) {
@@ -155,7 +157,7 @@ DropboxClient.prototype.putFile = function(file, path, optargs, cb) {
// Uploads contents to the specified path
DropboxClient.prototype.put = function(content, path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
- var uri = CONTENT_API_URI + '/files_put/dropbox/' + escapePath(path) +
+ var uri = CONTENT_API_URI + '/files_put/' + this.root + '/' + escapePath(path) +
'?' + stringifyParams(optargs);
this.put(uri, optargs, content, cb);
}
@@ -165,7 +167,7 @@ DropboxClient.prototype.put = function(content, path, optargs, cb) {
// Dropbox root.
DropboxClient.prototype.getMetadata = function(path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
- var uri = API_URI + '/metadata/dropbox/' + escapePath(path) + '?' +
+ var uri = API_URI + '/metadata/' + this.root + '/' + escapePath(path) + '?' +
stringifyParams(optargs);
this.get(uri, optargs, cb);
}
@@ -177,7 +179,7 @@ DropboxClient.prototype.getMetadata = function(path, optargs, cb) {
DropboxClient.prototype.getThumbnail = function(path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
optargs = optargs || {};
- var uri = CONTENT_API_URI + '/thumbnails/dropbox/' + escapePath(path) + '?' +
+ var uri = CONTENT_API_URI + '/thumbnails/' + this.root + '/' + escapePath(path) + '?' +
stringifyParams(optargs);
return this.get(uri, optargs, cb);
}
@@ -188,13 +190,10 @@ DropboxClient.prototype.getThumbnail = function(path, optargs, cb) {
// of arguments.
DropboxClient.prototype.copy = function(from_path, to_path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
- optargs.root = 'dropbox';
+ optargs.root = this.root;
if (!optargs.from_copy_ref) optargs.from_path = from_path;
optargs.to_path = to_path;
var uri = API_URI + '/fileops/copy?' + stringifyParams(optargs);
- querystring.stringify({root: 'dropbox'
- , from_path: from_path
- , to_path: to_path});
this.get(uri, optargs, cb);
}
@@ -205,7 +204,7 @@ DropboxClient.prototype.copy = function(from_path, to_path, optargs, cb) {
DropboxClient.prototype.createFolder = function(path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
var uri = API_URI + '/fileops/create_folder?' +
- querystring.stringify({root: 'dropbox'
+ querystring.stringify({root: this.root
, path: path});
this.get(uri, optargs, cb);
}
@@ -217,7 +216,7 @@ DropboxClient.prototype.createFolder = function(path, optargs, cb) {
DropboxClient.prototype.deleteItem = function(path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
var uri = API_URI + '/fileops/delete?' +
- querystring.stringify({root: 'dropbox', path: path});
+ querystring.stringify({root: this.root, path: path});
this.get(uri, optargs, cb);
}
@@ -228,7 +227,7 @@ DropboxClient.prototype.deleteItem = function(path, optargs, cb) {
DropboxClient.prototype.move = function(from_path, to_path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
var uri = API_URI + '/fileops/move?' +
- querystring.stringify({root: 'dropbox'
+ querystring.stringify({root: this.root
, from_path: from_path
, to_path: to_path});
this.get(uri, optargs, cb);
@@ -240,7 +239,7 @@ DropboxClient.prototype.move = function(from_path, to_path, optargs, cb) {
DropboxClient.prototype.search = function(path, query, optargs, cb) {
if (typeof optargs === 'function') cb = optargs, optargs = {};
optargs.query = query;
- var uri = API_URI + '/search/dropbox/' + escapePath(path) + '?' +
+ var uri = API_URI + '/search/' + this.root + '/' + escapePath(path) + '?' +
stringifyParams(optargs);
this.get(uri, optargs, cb);
}

0 comments on commit 01a6f06

Please sign in to comment.