From dd8813a4418d2929166d751e10ac27c17db590bf Mon Sep 17 00:00:00 2001 From: Evan Meagher Date: Sat, 16 Oct 2010 12:32:47 -0700 Subject: [PATCH] Added account info getter method. Restructured client object construction. Started work on file-upload method. --- lib/dropbox-node/index.js | 55 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/dropbox-node/index.js b/lib/dropbox-node/index.js index 4d061ea..34f0a1e 100644 --- a/lib/dropbox-node/index.js +++ b/lib/dropbox-node/index.js @@ -12,33 +12,28 @@ var http = require('http'), access_token = '', access_token_secret = '' -// TODO: Write method header -var DropboxClient = exports.DropboxClient = function(options) { - events.EventEmitter.call(this) - if (!options) options = {} - this.oauth = options.oauth - this.access_token = options.access_token - this.access_token_secret = options.access_token_secret +// +var DropboxClient = exports.DropboxClient = function(oauth, + access_token, + access_token_secret) { + this.oauth = oauth + this.access_token = access_token + this.access_token_secret = access_token_secret } -sys.inherits(DropboxClient, events.EventEmitter) - -// Get metadata of file/folder specified by path relative to Dropbox -// root directory. -DropboxClient.prototype.getMetadata = function(path, callback) { - var self = this +// Retrieves information about the user's account. +DropboxClient.prototype.getAccountInfo = function(callback) { this.oauth.getProtectedResource( - API_URI + API_VERSION + '/metadata/dropbox/' + path, + API_URI + API_VERSION + '/account/info/', 'GET', this.access_token, this.access_token_secret, function(err, data, res) { callback(err, data) }) } -// Get contents of a file, specified by path parameter, relative to -// Dropbox root directory. +// Get contents of a file specified by path parameter, relative to +// user's Dropbox root. DropboxClient.prototype.getFile = function(path, callback) { - var self = this this.oauth.getProtectedResource( CONTENT_API_URI + API_VERSION + '/files/dropbox/' + path, 'GET', this.access_token, this.access_token_secret, @@ -46,3 +41,29 @@ DropboxClient.prototype.getFile = function(path, callback) { callback(err, data) }) } + +// Uploads contents of a file specified by path parameter, relative to +// application's directory. +DropboxClient.prototype.putFile = function(file, path, callback) { + var signed_filename = this.oauth.signUrl(file, this.access_token, + this.access_token_secret, 'POST') + console.log('signed_filename: ' + signed_filename) + console.log('uri: ' + CONTENT_API_URI + API_VERSION + '/files/dropbox/' + path + '?file=' + file) + this.oauth.getProtectedResource( + CONTENT_API_URI + API_VERSION + '/files/dropbox/' + path + '?file=' + file, + 'POST', this.access_token, this.access_token_secret, + function(err, data, res) { + callback(err, data) + }) +} + +// Get metadata of file/folder specified by path relative to user's +// Dropbox root. +DropboxClient.prototype.getMetadata = function(path, callback) { + this.oauth.getProtectedResource( + API_URI + API_VERSION + '/metadata/dropbox/' + path, + 'GET', this.access_token, this.access_token_secret, + function(err, data, res) { + callback(err, data) + }) +}