Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

RDropbox: A Ruby Client Library for Dropbox

By Peter Cooper / May 5, 2010

Dropbox is a popular file hosting service (4m+ users) that provides synced backup and file hosting to OS X, Windows, and Linux users. You get up to 2GB of space for free. RDropbox is a library by Tim Morgan (of Autumn fame) that takes advantage of the official Dropbox API from Ruby.

With RDropbox you can log into a Dropbox account using OAuth and then upload and download files. A requirement, however, is that you apply for Dropbox API access and are approved, as the API is not fully open to the public without going through the approval process (this appears to be in order to avoid overloading their service). The API was, notably, worked on by notable Ruby alumnus, *** ****.

Once you've made it into the Dropbox API program, RDropbox gives you the benefit of writing code as simple as:

# STEP 1: Authorize the user
session = Dropbox::Session.new('your_consumer_key', 'your_consumer_secret')
puts "Visit #{session.authorize_url} to log in to Dropbox. Hit enter when you have done this."
gets
session.authorize
session.sandbox = true

# STEP 2: Play!
session.upload('testfile.txt')
uploaded_file = session.file('testfile.txt')
puts uploaded_file.metadata.size

uploaded_file.move 'new_name.txt'
uploaded_file.delete

An alternative, unofficial route: tvongaza's DropBox

If you want to be using Dropbox from Ruby right now, there's an alternative: tvongaza/DropBox. This alternative library predates the official Dropbox API and uses the same techniques as the official Dropbox clients instead. For this you'll need to use your Dropbox e-mail username and password to log in (this could be a problem if you want to use third party Dropbox accounts!) and you can then create, delete and rename folders and files, as well as check usage statistics.

Comments

  1. Sohan says:

    Your post has been linked at DrinkRails.com as one of the top ruby on rails blogs of the day.

  2. Pican says:

    I have used Dropbox for a while, it's so convenient:>

  3. Jeff says:

    I am overly excited about this -- we'll see if my application to access the API had sufficient begging.

Other Posts to Enjoy

Twitter Mentions