• Stars
    star
    513
  • Rank 85,811 (Top 2 %)
  • Language
    JavaScript
  • Created almost 13 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NodeJS SDK for Dropbox API (THIS LIBRARY IS OBSOLETE!!)

dbox (THIS LIBRARY IS V1 ONLY WHICH IS NOW OBSOLETE!!)

A Node.JS convenience wrapper around the Dropbox API. Simplifies OAuth handshake and removes HTTP ceremony.

Installation

I always recommend you bundle your dependencies with your application. To do this, create a package.json file in the root of your project with the minimum information...

{
  "name": "yourapplication",
  "version": "0.1.0",
  "dependencies": {
    "dbox": "0.6.1"
  }
}

Then run the following command using npm...

npm install

OR, if you just want to start playing with the library run...

npm install dbox

API Overview

dbox methods (where dbox is set from requiring the dbox library)...

app                 <-- creates application object

app methods (where app is created from the above app call)...

requesttoken        <-- creates request token for getting request token and authorization url
accesstoken         <-- creates access token for creating a client object
client              <-- creates client object with access to users dropbox account

client methods (where client is created from the above client call)...

account             <-- view account
mkdir               <-- make directory
mv                  <-- move file or directory
cp                  <-- copy file or directory
rm                  <-- remove file or directory
put                 <-- upload file
get                 <-- download file
metadata            <-- get file or directory information
revisions           <-- get revision history
restore             <-- restore previous version
search              <-- search directory
shares              <-- create link to view file
media               <-- create streamable link to file
thumbnails          <-- get thumbnail of file
copyref             <-- create copy reference to file
delta               <-- get list of delta entries
stream              <-- creates readable stream
readdir             <-- recursively reads directory

How to Use

Creating a functional dbox client is a four step process.

  1. create an app using application credentials provided by dropbox
  2. obtain request token to use for generation access token
  3. have user visit authorization URL to grant access to your application
  4. create a client using access token that was generated earlier

Step 1

var dbox  = require("dbox")
var app   = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6" })

Step 2

Authorization is a three step process.

a) Get a request token...

app.requesttoken(function(status, request_token){
  console.log(request_token)
})

b) User must visit the url to grant authorization to the client...

https://www.dropbox.com/1/oauth/authorize?oauth_token=#{ request_token.oauth_token }

c) Generate our access token with the request token...

app.accesstoken(request_token, function(status, access_token){
  console.log(access_token)
})

Step 3

var client = app.client(access_token)

Now we have a client that gives us access to all the api functionality.

Client Methods

account([options,] callback)

Returns account information.

client.account(function(status, reply){
  console.log(reply)
})

output of reply returns...

{ 
  uid: 123456789,
  display_name: 'Brock Whitten',
  email: '[email protected]',
  country: 'CA',
  referral_link: 'https://www.dropbox.com/referrals/NTc0NzYwNDc5',
  quota_info: { 
    shared: 1100727791, 
    quota: 2415919104, 
    normal: 226168599
  }
}

mkdir(path, [options,] callback)

Creates directory at specified location.

client.mkdir("foo", options, function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "size": "0 bytes",
  "rev": "1f477dd351f",
  "thumb_exists": false,
  "bytes": 0,
  "modified": "Wed, 10 Aug 2011 18:21:30 +0000",
  "path": "/foo",
  "is_dir": true,
  "icon": "folder",
  "root": "sandbox",
  "revision": 5023410
}

mv(from_path, to_path, [options,] callback)

Moves file or directory to a new location.

client.mv("foo", "bar", function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "size": "0 bytes",
  "rev": "irt77dd3728",
  "thumb_exists": false,
  "bytes": 0,
  "modified": "Wed, 10 Aug 2011 18:21:30 +0000",
  "path": "/bar",
  "is_dir": true,
  "icon": "folder",
  "root": "sandbox",
  "revision": 5023410
}

cp(from_path, to_path, [options,] callback)

Copies a file or directory to a new location.

client.cp("bar", "baz", function(status, reply){
  console.log(reply)
})

{
  "size": "0 bytes",
  "rev": "irt77dd3728",
  "thumb_exists": false,
  "bytes": 0,
  "modified": "Wed, 10 Aug 2011 18:21:30 +0000",
  "path": "/baz",
  "is_dir": true,
  "icon": "folder",
  "root": "sandbox",
  "revision": 5023410
}

rm(path, [options,] callback)

Removes a file or directory.

client.rm("README.txt", function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "size": "0 bytes",
  "is_deleted": true,
  "bytes": 0,
  "thumb_exists": false,
  "rev": "1f33043551f",
  "modified": "Wed, 10 Aug 2011 18:21:30 +0000",
  "path": "/README.txt",
  "is_dir": false,
  "icon": "page_white_text",
  "root": "sandbox",
  "mime_type": "text/plain",
  "revision": 492341
}

put(path, data, [options,] callback)

Creates or modifies a file with given data. data may be a string or a buffer.

client.put("foo/hello.txt", "here is some text", function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "size": "225.4KB",
  "rev": "35e97029684fe",
  "thumb_exists": false,
  "bytes": 230783,
  "modified": "Tue, 19 Jul 2011 21:55:38 +0000",
  "path": "/foo/hello.txt",
  "is_dir": false,
  "icon": "page_white_text",
  "root": "sandbox",
  "mime_type": "text/plain",
  "revision": 220823
}

get(path, [options,] callback)

Pulls down file (available as a buffer) with its metadata.

client.get("foo/hello.txt", function(status, reply, metadata){
  console.log(reply.toString(), metadata)
})

output of reply.toString() returns...

here is some text

output of metadata returns...

{
  "revision": 11,
  "rev": "b07a93bb3",
  "thumb_exists": false,
  "bytes": 17,
  "modified": "Sat, 12 May 2012 19:31:08 +0000",
  "client_mtime": "Sat, 12 May 2012 19:30:52 +0000",
  "path": "/foo/hello.txt",
  "is_dir": false,
  "icon": "page_white_text",
   "root": "app_folder",
   "mime_type": "text/plain",
  "size": "17 bytes"
}

metadata(path, [options,] callback)

Retrieves file or directory metadata.

// available options...
var options = {
  file_limit         : 10000,              // optional
  hash               : ...,                // optional
  list               : true,               // optional
  include_deleted    : false,              // optional
  rev                : 7,                  // optional
  locale:            : "en",               // optional
  root:              : "sandbox"           // optional
}

client.metadata("Getting_Started.pdf", options, function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "size": "225.4KB",
  "rev": "35e97029684fe",
  "thumb_exists": false,
  "bytes": 230783,
  "modified": "Tue, 19 Jul 2011 21:55:38 +0000",
  "path": "/Getting_Started.pdf",
  "is_dir": false,
  "icon": "page_white_acrobat",
  "root": "sandbox",
  "mime_type": "application/pdf",
  "revision": 220823
}

revisions(path, [options,] callback)

Obtains metadata for the previous revisions of a file.

// available options...
var options = {
  rev_limit          : 10,                 // optional
  locale:            : "en"                // optional
}

client.revisions("foo/hello.txt", options, function(status, reply){
  console.log(reply)
})

output of reply returns...

[
  {
    "is_deleted": true,
    "revision": 4,
    "rev": "40000000d",
    "thumb_exists": false,
    "bytes": 0,
    "modified": "Wed, 20 Jul 2011 22:41:09 +0000",
    "path": "foo/hello.txt",
    "is_dir": false,
    "icon": "page_white",
    "root": "sandbox",
    "mime_type": "text/plain",
    "size": "0 bytes"
  },
  {
    "revision": 1,
    "rev": "10000000d",
    "thumb_exists": false,
    "bytes": 3,
    "modified": "Wed, 20 Jul 2011 22:40:43 +0000",
    "path": "foo/hello.txt",
    "is_dir": false,
    "icon": "page_white",
    "root": "sandbox",
    "mime_type": "text/plain",
    "size": "3 bytes"
  }
]

restore(path, rev, [options,] callback)

Restores a file path to a previous revision.

client.revisions("foo/hello.txt", 4, function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "is_deleted": true,
  "revision": 4,
  "rev": "40000000d",
  "thumb_exists": false,
  "bytes": 0,
  "modified": "Wed, 20 Jul 2011 22:41:09 +0000",
  "path": "/foo/hello.txt",
  "is_dir": false,
  "icon": "page_white",
  "root": "sandbox",
  "mime_type": "text/plain",
  "size": "0 bytes"
}

search(path, query, [options,] callback)

Returns metadata for all files and directories that match the search query.

var options = {
  file_limit         : 10000,              // optional
  include_deleted    : false,              // optional
  locale:            : "en"                // optional
}

client.search("foo", "hello", options, function(status, reply){
  console.log(reply)
})

output of reply returns...

[
  {
    "size": "0 bytes",
    "rev": "35c1f029684fe",
    "thumb_exists": false,
    "bytes": 0,
    "modified": "Mon, 18 Jul 2011 20:13:43 +0000",
    "path": "/foo/hello.txt",
    "is_dir": false,
    "icon": "page_white_text",
    "root": "sandbox",
    "mime_type": "text/plain",
    "revision": 220191
  }
]

shares(path, [options,] callback)

Creates and/or returns a shareable link to a file or directory.

client.shares("foo/hello.txt", options, function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "url": "http://db.tt/APqhX1",
  "expires": "Sat, 17 Aug 2011 02:34:33 +0000"
}

media(path, [options,] callback)

Creates and/or returns a shareable link to a file or directory. This endpoint is similar to /shares but content is streamable.

client.media("foo/hello.txt", function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  "url": "http://www.dropbox.com/s/m/a2mbDa2",
  "expires": "Thu, 16 Sep 2011 01:01:25 +0000"
}

thumbnails(path, [options,] callback)

Gets a thumbnail for an image.

client.thumbnails("foo/koala.jpg", function(status, reply, metadata){
  console.log(metadata);

  require('fs').writeFile('koala_small.jpg', reply, function () {
    console.log('Thumbnail saved!');
  });
})

output of reply is a buffer which should be sent to a new image file.

output of metadata returns...

{
  "revision": 13,
  "rev": "d07a93bb3",
  "thumb_exists": true,
  "bytes": 780831,
  "modified": "Sat, 12 May 2012 19:48:59 +0000",
  "client_mtime": "Tue, 14 Jul 2009 05:32:31 +0000",
  "path": "/foo/koala.jpg",
  "is_dir": false,
  "icon": "page_white_picture",
  "root": "app_folder",
  "mime_type": "image/jpeg",
  "size": "762.5 KB"
} 

cpref(path, [options,] callback)

client.cpref("song.mp3", function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  expires: 'Thu, 03 Apr 2042 22:33:49 +0000',
  copy_ref: 'ALGf72Jrc3A0ZTh5MzA4Mg'
}

delta([options,] callback)

client.delta(function(status, reply){
  console.log(reply)
})

output of reply returns...

{
  reset: true,
  cursor: 'AkMCE0f1CsMA7tobhXR1vwEZaM1KjFqTNjxgWITCks6oeJxjKBL2Z2Co0WOp_rSOgYHxJwMQAAAyKwSY',
  has_more: false,
  entries: [
    [ '/foo', [Object] ],
    [ '/bar', [Object] ]
  ]
}

readdir(path, callback)

Get an array of paths for all files and directories found in the given path. The method calls recursively to dropbox so it can take a long time to evaluate.

client.readdir('/', function(status, reply){
    console.log(reply)
})

Output of readdir returns...

['/','/foo','/bar']

License

Copyright 2011 Chloi Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

harp

Static Web Server/Generator/Bundler
JavaScript
4,995
star
2

surge

CLI for the surge.sh CDN
JavaScript
2,861
star
3

phonegap

access core functions on Android, iPhone and Blackberry using JavaScript
JavaScript
2,104
star
4

terraform

Asset pipeline for the Harp Web Server.
JavaScript
102
star
5

learn-ruby

files for learning ruby. quickly.
Ruby
79
star
6

nhl

a screen scraping nhl.com api (this project was created as a demonstration)
JavaScript
70
star
7

rolodex

Node user management system using redis
JavaScript
42
star
8

phonegap-examples

open source phonegap examples go here
JavaScript
33
star
9

thug

ORM replacement that provides a functional style object filtration and validation system.
JavaScript
20
star
10

pmpknpi

A RESTful Blog API written in Merb
JavaScript
19
star
11

node-redis-tag

Node tag system using redis.
JavaScript
18
star
12

waterfront

A generic message broker system on top of ZeroMQ with discovery patterns for push/pull, req/rep, pub/sub.
JavaScript
18
star
13

git-harvest

github hook for posting time to harvest
Ruby
16
star
14

node-redis-authorization

Node authorization system built on redis.
JavaScript
12
star
15

phonegap-docs

hand written docs for phonegap and xui
JavaScript
11
star
16

statuscodedrinkinggame

drinking game API built on Smart Platform
JavaScript
8
star
17

smart-messagepub

send AIM, Google Chat, Email, Twitter, Phone, and SMS on the smart platform.
JavaScript
7
star
18

hb-browserify

a boilerplate project for using harp with browserify.
HTML
7
star
19

alluvium

time-series analytics for static web sites.
JavaScript
6
star
20

pressman

email templating system
JavaScript
6
star
21

merb_can_filter

merb plugin for filtering Markdown or Textile to HTML (also does syntax highlighting via coderay).
Ruby
5
star
22

gambit

A minimal mobile UX navigation library for html5 mobile web and cordova applications.
JavaScript
5
star
23

yonder

Redirects for front-end applications. Works on surge.sh.
JavaScript
5
star
24

very-old-phonegap-and-xuijs-websites

stumbled on this old repo late one night. decided to publish it.
JavaScript
5
star
25

refuze

A natural language job queue for doing things later. Built on Redis.
JavaScript
5
star
26

exhale

expiring token system for ephemeral tasks such as email verification and password reset
JavaScript
5
star
27

microplatform

JavaScript
4
star
28

smart-helpers

layout, form, and date helpers for Joyent Smart Platform
JavaScript
4
star
29

yoke

preprocessor for language agnostic concatenation
JavaScript
4
star
30

merb_bot_test

Quick and dirty spam protection using a math equation.
Ruby
3
star
31

merbums

Merb powered forum inspired by Beast
Ruby
3
star
32

nwo

another web publishing tool by sintaxi
JavaScript
3
star
33

aria

A client library for Aria API
JavaScript
3
star
34

hb-minimal

A minimal boilerplate for the Harp Application
3
star
35

urlinfo-server

a service for providing information on any given url
JavaScript
3
star
36

ru

dunno what this is
JavaScript
2
star
37

smart-platform

Joyent Smart Platform
Perl
2
star
38

node-timerange

returns start and end timestamps for YYYY-MM-DD, YYYY-MM, or YYYY
JavaScript
2
star
39

sintaxi.github.com

github can blog
JavaScript
2
star
40

start

CSS
2
star
41

surge-sdk

JavaScript SDK used by Surge.sh CLI
JavaScript
2
star
42

pwa

JavaScript
2
star
43

harp-boilerplates

CLI for searching the Harp Boilerplates registry.
JavaScript
1
star
44

vanjs.no.de

chat example using redis, socket.io, express
JavaScript
1
star
45

nhl-client

CSS
1
star
46

virtual-dom-starter

bare-bones virtual-dom starter using main-loop and browserify/watchify with npm run scripts
JavaScript
1
star
47

localci

test runner for front-end web projects
1
star
48

popp

command line tool to pluck the first line out of file
JavaScript
1
star
49

foxy

a simple proxy middle for CORS
JavaScript
1
star
50

cldflr

static publishing to surge.sh fronted by cloudflare
JavaScript
1
star
51

roller

an example on how to use rolodex
JavaScript
1
star