Skip to content

Commit

Permalink
Added account info getter method. Restructured client object construc…
Browse files Browse the repository at this point in the history
…tion. Started work on file-upload method.
  • Loading branch information
evnm committed Oct 16, 2010
1 parent aaae1c7 commit dd8813a
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions lib/dropbox-node/index.js
Expand Up @@ -12,37 +12,58 @@ 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,
function(err, data, res) {
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)
})
}

0 comments on commit dd8813a

Please sign in to comment.