Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

resolves conflict in copy_ref merge

  • Loading branch information...
commit e857a793360234a9e9904cdee5a786dd418d5786 1 parent a94cc42
@sintaxi authored
Showing with 325 additions and 217 deletions.
  1. +2 −0  .gitignore
  2. +322 −217 dbox.js
  3. +1 −0  lib/oauth.js
View
2  .gitignore
@@ -1,4 +1,6 @@
.DS_Store
node_modules
+test
+tmp
*.swp
*.*~
View
539 dbox.js
@@ -2,7 +2,7 @@ var request = require("request")
var oauth = require("./lib/oauth")
var qs = require("querystring")
-exports.createClient = function(config){
+exports.app = function(config){
var sign = oauth(config.app_key, config.app_secret)
var root = config.root || "sandbox"
@@ -18,16 +18,12 @@ exports.createClient = function(config){
"body": qs.stringify(signature)
}
request(args, function(e, r, b){
- cb(e ? null : r.statusCode, qs.parse(b))
+ var obj = qs.parse(b)
+ obj.authorize_url = "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + obj.oauth_token
+ cb(e ? null : r.statusCode, obj)
})
},
- build_authorize_url: function(oauth_token, oauth_callback){
- var url = "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + oauth_token;
- if(oauth_callback){
- url = url + "&oauth_callback=" + oauth_callback;
- }
- return url;
- },
+
access_token: function(options, cb){
var params = sign(options)
var args = {
@@ -41,239 +37,348 @@ exports.createClient = function(config){
})
},
- account: function(options, cb){
- var params = sign(options)
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/account/info",
- "body": qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
-
- delta: function(options, cb){
- var params = sign(options)
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/delta",
- "body": qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(r.statusCode, JSON.parse(b))
- })
- },
+ createClient: function(options){
+ var options = options
- get: function(path, options, cb){
- var params = sign(options)
+ return {
+ account: function(cb){
+ var params = sign(options)
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/account/info",
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
+
+ delta: function(args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/delta",
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- var args = {
- "method": "GET",
- "url": "https://api-content.dropbox.com/1/files/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
- "encoding": null
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
+ get: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "GET",
+ "url": "https://api-content.dropbox.com/1/files/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
+ "encoding": null
+ }
+ request(args, function(e, r, b){
+ cb(r.statusCode, b)
+ })
+ },
- put: function(path, body, options, cb){
- var params = sign(options)
- var args = {
- "method": "PUT",
- "headers": { "content-length": body.length },
- "url": "https://api-content.dropbox.com/1/files_put/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
- "body": body
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
+ put: function(path, body, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "PUT",
+ "headers": { "content-length": body.length },
+ "url": "https://api-content.dropbox.com/1/files_put/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
+ "body": body
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- metadata: function(path, options, cb){
- var params = sign(options)
- var args = {
- "method": "GET",
- "url": "https://api.dropbox.com/1/metadata/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
+ metadata: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "GET",
+ "url": "https://api.dropbox.com/1/metadata/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- revisions: function(path, options, cb){
- var params = sign(options)
- var args = {
- "method": "GET",
- "url": "https://api.dropbox.com/1/revisions/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
+ revisions: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "GET",
+ "url": "https://api.dropbox.com/1/revisions/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- restore: function(path, rev, options, cb){
- var params = sign(options)
- params["rev"] = rev
+ restore: function(path, rev, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["rev"] = rev
- var body = qs.stringify(params)
- var args = {
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded",
- "content-length": body.length
+ var body = qs.stringify(params)
+ var args = {
+ "method": "POST",
+ "headers": {
+ "content-type": "application/x-www-form-urlencoded",
+ "content-length": body.length
+ },
+ "url": "https://api.dropbox.com/1/restore/" + (params.root || root) + "/" + qs.escape(path), // + "?" + qs.stringify(params)
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
},
- "url": "https://api.dropbox.com/1/restore/" + (params.root || root) + "/" + qs.escape(path), // + "?" + qs.stringify(params)
- "body": qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
- search: function(path, query, options, cb){
- var params = sign(options)
- params["query"] = query
+ search: function(path, query, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["query"] = query
- var body = qs.stringify(params)
- var args = {
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded",
- "content-length": body.length
+ var body = qs.stringify(params)
+ var args = {
+ "method": "POST",
+ "headers": {
+ "content-type": "application/x-www-form-urlencoded",
+ "content-length": body.length
+ },
+ "url": "https://api.dropbox.com/1/search/" + (params.root || root) + "/" + qs.escape(path),
+ "body": body
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
},
- "url": "https://api.dropbox.com/1/search/" + (params.root || root) + "/" + qs.escape(path),
- "body": body
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
- shares: function(path, options, cb){
- var params = sign(options)
- var body = qs.stringify(params)
- var args = {
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded",
- "content-length": body.length
+ shares: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var body = qs.stringify(params)
+ var args = {
+ "method": "POST",
+ "headers": {
+ "content-type": "application/x-www-form-urlencoded",
+ "content-length": body.length
+ },
+ "url": "https://api.dropbox.com/1/shares/" + (params.root || root) + "/" + qs.escape(path),
+ "body": body
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
},
- "url": "https://api.dropbox.com/1/shares/" + (params.root || root) + "/" + qs.escape(path),
- "body": body
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
- media: function(path, options, cb){
- var params = sign(options)
- var body = qs.stringify(params)
- var args = {
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded",
- "content-length": body.length
+ media: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var body = qs.stringify(params)
+ var args = {
+ "method": "POST",
+ "headers": {
+ "content-type": "application/x-www-form-urlencoded",
+ "content-length": body.length
+ },
+ "url": "https://api.dropbox.com/1/media/" + (params.root || root) + "/" + qs.escape(path),
+ "body": body
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
},
- "url": "https://api.dropbox.com/1/media/" + (params.root || root) + "/" + qs.escape(path),
- "body": body
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
- copy_ref: function(path, options, cb){
- var params = sign(options)
- var args = {
- "method": "GET",
- "url": "https://api.dropbox.com/1/copy_ref/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
+ copy_ref: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "GET",
+ "url": "https://api.dropbox.com/1/copy_ref/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- thumbnails: function(path, options, cb){
- var params = sign(options)
- var args = {
- "method": "GET",
- "url": "https://api-content.dropbox.com/1/thumbnails/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
- "encoding": null
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, b)
- })
- },
+ thumbnails: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ var args = {
+ "method": "GET",
+ "url": "https://api-content.dropbox.com/1/thumbnails/" + (params.root || root) + "/" + qs.escape(path) + "?" + qs.stringify(params),
+ "encoding": null
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, b)
+ })
+ },
- cp: function(from_path, to_path, options, cb){
- var params = sign(options)
- params["root"] = params.root || root
- params["from_path"] = from_path

cp() also accepts a copy_ref value in which case from_path param becomes "from_copy_ref". I can think of a few options for handling the switch but they're not super elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- params["to_path"] = to_path
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/fileops/copy",
- "body": qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
+ cp: function(from_path, to_path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["root"] = params.root || root
+ params["from_path"] = from_path
+ params["to_path"] = to_path
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/fileops/copy",
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- mv: function(from_path, to_path, options, cb){
- var params = sign(options)
- params["root"] = params.root || root
- params["from_path"] = from_path
- params["to_path"] = to_path
+ mv: function(from_path, to_path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["root"] = params.root || root
+ params["from_path"] = from_path
+ params["to_path"] = to_path
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/fileops/move",
- "body": qs.stringify(params)
- }
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/fileops/move",
+ "body": qs.stringify(params)
+ }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- rm: function(path, options, cb){
- var params = sign(options)
- params["root"] = params["root"] || root
- params["path"] = path
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/fileops/delete",
- "body": qs.stringify(params)
- }
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
- },
+ rm: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["root"] = params["root"] || root
+ params["path"] = path
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/fileops/delete",
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ },
- mkdir: function(path, options, cb){
- var params = sign(options)
- params["root"] = params.root || root
- params["path"] = path
- var args = {
- "method": "POST",
- "headers": { "content-type": "application/x-www-form-urlencoded" },
- "url": "https://api.dropbox.com/1/fileops/create_folder",
- "body": qs.stringify(params)
+ mkdir: function(path, args, cb){
+ if(cb == null){
+ cb = args
+ }else{
+ for(var attr in args)(function(attr){
+ options[attr] = args[attr]
+ })(attr)
+ }
+ var params = sign(options)
+ params["root"] = params.root || root
+ params["path"] = path
+ var args = {
+ "method": "POST",
+ "headers": { "content-type": "application/x-www-form-urlencoded" },
+ "url": "https://api.dropbox.com/1/fileops/create_folder",
+ "body": qs.stringify(params)
+ }
+ request(args, function(e, r, b){
+ cb(e ? null : r.statusCode, JSON.parse(b))
+ })
+ }
}
- request(args, function(e, r, b){
- cb(e ? null : r.statusCode, JSON.parse(b))
- })
}
-
}
}
View
1  lib/oauth.js
@@ -36,6 +36,7 @@ module.exports = function (consumerKey, consumerSecret){
options["oauth_signature_method"] = "PLAINTEXT",
options["oauth_version"] = "1.0"
+ delete options["authorize_url"]
delete options["oauth_token_secret"]
delete options["uid"]
Please sign in to comment.
Something went wrong with that request. Please try again.