diff --git a/README.md b/README.md index 11c4395..c9415be 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,9 @@ Creating a functional `dbox` client is a four step process. ### Step 1 var dbox = require("dbox") - var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6" }) + var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6"[, "root": "sandbox"] }) + +_NB_: the root parameter is to change between the two different dropbox app types there are. `sandbox` means 'App folder' and `dropbox` means 'Full Dropbox', default is `sandbox`. ### Step 2 diff --git a/dbox.js b/dbox.js index 9f6a143..f6ab0aa 100644 --- a/dbox.js +++ b/dbox.js @@ -489,4 +489,3 @@ exports.app = function(config){ } } - diff --git a/test/all.js b/test/all.js index 437a3f6..45bf329 100644 --- a/test/all.js +++ b/test/all.js @@ -9,6 +9,7 @@ describe("all", function(){ var client, ref; before(function(done){ + this.timeout(20000); //To give the testrunner time for accepting the dropbox access helpers.auth(app, function(access_token){ client = app.client(access_token) done() diff --git a/test/config/app.json.sample b/test/config/app.json.sample index 048e3a8..a70cc26 100644 --- a/test/config/app.json.sample +++ b/test/config/app.json.sample @@ -1,4 +1,5 @@ { "app_key": "", - "app_secret": "" + "app_secret": "", + "root": "sandbox" } \ No newline at end of file diff --git a/test/config/helpers.js b/test/config/helpers.js index 995305d..fb23e1e 100644 --- a/test/config/helpers.js +++ b/test/config/helpers.js @@ -2,24 +2,32 @@ var fs = require("fs") var prompt = require("prompt") exports.auth = function(app, callback){ - var token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json")) - var client = app.client(token) - client.account(function(status, account){ - if(status == 200){ - callback(token) - }else{ - app.requesttoken(function(status, request_token){ - prompt.start() - prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) { - if (err) { return 1 } - app.accesstoken(request_token, function(status, access_token){ - fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){ - if (err) throw err; - callback(access_token) - }) + var makeNewAccessToken = function() { + app.requesttoken(function(status, request_token){ + prompt.start() + prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) { + if (err) { return 1 } + app.accesstoken(request_token, function(status, access_token){ + fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){ + if (err) throw err; + callback(access_token) }) }) - }) - } - }) + }) + }) + } + + if (fs.existsSync(__dirname + "/access_token.json")) { + var access_token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json")) + var client = app.client(access_token) + client.account(function(status, account){ + if(status == 200){ + callback(access_token) + }else{ + makeNewAccessToken(); + } + }) + } else { + makeNewAccessToken(); + } } \ No newline at end of file