• This repository has been archived on 04/May/2018
  • Stars
    star
    519
  • Rank 85,261 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 15 years ago
  • Updated over 12 years ago

Reviews

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

Repository Details

An easy-to-use client library for the official Dropbox API.

Ruby Dropbox Gem¶ ↑

An easy-to-use third-party interface to the RESTful Dropbox API.

Installation¶ ↑

gem install dropbox

Tutorial by Example¶ ↑

First things first: Be sure you’ve gotten a consumer key and secret from developers.dropbox.com

# STEP 1: Authorize the user
session = Dropbox::Session.new('your_consumer_key', 'your_consumer_secret')
session.mode = :sandbox # might need to set this to :dropbox; consult your API account page
puts "Visit #{session.authorize_url} to log in to Dropbox. Hit enter when you have done this."
gets
session.authorize

# 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

# STEP 3: Save session for later
File.open('serialized_session.txt', 'w') do |f|
  f.puts session.serialize
end

# STEP 4: Play with saved session!
new_session = Dropbox::Session.deserialize(File.read('serialized_session.txt'))
account = new_session.account
puts account.display_name

Tutorial by Example, Rails Edition¶ ↑

A simple Rails controller that allows a user to first authorize their Dropbox account, and then upload a file to their Dropbox.

class DropboxController < ApplicationController
  def authorize
    if params[:oauth_token] then
      dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
      dropbox_session.authorize(params)
      session[:dropbox_session] = dropbox_session.serialize # re-serialize the authenticated session

      redirect_to :action => 'upload'
    else
      dropbox_session = Dropbox::Session.new('your_consumer_key', 'your_consumer_secret')
      session[:dropbox_session] = dropbox_session.serialize
      redirect_to dropbox_session.authorize_url(:oauth_callback => url_for(:action => 'authorize'))
    end
  end

  def upload
    return redirect_to(:action => 'authorize') unless session[:dropbox_session]
    dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
    return redirect_to(:action => 'authorize') unless dropbox_session.authorized?

    if request.method == :post then
      dropbox_session.upload params[:file], 'My Uploads'
      render :text => 'Uploaded OK'
    else
      # display a multipart file field form
    end
  end
end

Features and Where to Find Them¶ ↑

  • Start with the Dropbox::Session class. The first thing you should do is authenticate your users and that class is how to do it.

  • The Dropbox::API module (attached to the Dropbox::Session class) is the meat and potatoes. Use it to modify a user’s Dropbox.

  • The Dropbox::Entry class is a more object-oriented way of manipulating files. It’s totally optional; check it out if you like OOP.

  • The Dropbox::Memoization module has some handy utility methods for memoizing server responses to reduce network calls. It’s plug-in compatible with any caching strategy you might already have (memcache, etc.).

  • If you’re using pingbacks, check out Dropbox::Event and Dropbox::Revision. Those classes parse pingbacks from Dropbox into Ruby objects.

Testing Your Code¶ ↑

The gem is fully specced. Run specs with +rake spec+. Before doing so, you will need to create a file called keys.json in the project root containing your Dropbox API key and secret, as well as the email and password for a Dropbox account. See the keys.json.example file to get started.

fguillen has implemented a mock of the Dropbox API server: github.com/fguillen/DummyDropbox

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Tim Morgan. See LICENSE for details.

More Repositories

1

autumn

Easy, fresh, feature-rich IRC bots in Ruby
Ruby
222
star
2

slugalicious

Easy-to-use and powerful slugging for Rails 3
Ruby
32
star
3

hierarchy

Use PostgreSQL LTREE type with ActiveRecord
Ruby
25
star
4

enum_type

PostgreSQL enumerated types in ActiveRecord
Ruby
21
star
5

SFBayAreaFFContentPack

San Francisco Bay Area pilots’ content pack for ForeFlight
15
star
6

Configoro

Configuration object and YAML-based storage for Rails apps
Ruby
14
star
7

sql_origin

Add backtraces to your query log and queries themselves.
Ruby
13
star
8

SwiftMETAR

A METAR and TAF parser in Swift
Swift
12
star
9

multiuploader

A drag-and-drop, multi-streaming, strictly-HTML5 file uploader for Rails apps
Ruby
8
star
10

url_validation

Rails 3.0 EachValidator for checking URLs (syntax, connectivity, response code, ...)
Ruby
8
star
11

SwiftNASR

Parser for FAA aeronautical data (NASR)
Swift
7
star
12

better_caller

Symbolic call stack with bindings
C
7
star
13

icrashedmyplane.com

A website to help people navigate NTSB 830
TypeScript
7
star
14

has_metadata_column

Reduce your table width and migration overhead by moving non-indexed columns to a separate metadata column.
Ruby
5
star
15

learnmorse.codes

Learning Morse code is fun!
TypeScript
5
star
16

ip_address_validator

Rails 3 EachValidator for IPv4 and IPv6 addresses
Ruby
5
star
17

BadBehavior

A Swift script that scans your LogTen Pro X logbook for illegal flights
Swift
5
star
18

subdomain_router

Use dynamic subdomains in your Rails website
Ruby
5
star
19

email_validation

Simple email validation in Rails 3
Ruby
5
star
20

AvFacts

This website is the home of AvFacts, a podcast about all things aviation
Ruby
4
star
21

autumn-websearcher

Simple IRC bot (for Autumn) that performs Google web/image/news searches
Ruby
4
star
22

carousel

An Ajax-powered image carousel for Rails apps.
Ruby
4
star
23

twentyfour

Cocoa Mac application that changes your desktop depending on the time of day
CSS
4
star
24

validates_im

A set of Rails validators for common instant messenging services
Ruby
4
star
25

TMMoveToApplicationsFolder

Lets a Cocoa application move itself to the /Applications folder when first launched
3
star
26

Cirrus-AMM-Generator

Generates a single PDF from the collection of Cirrus AMM PDFs
Swift
3
star
27

METAR-Decoder

Decodes METAR remarks.
Objective-C
3
star
28

SF50-TOLD

SF50 Takeoff and Landing Data
Swift
3
star
29

has_metadata

Reduce your table width by moving non-indexed columns to a separate metadata table
Ruby
3
star
30

giffy

A Rails-based Slack bot
Ruby
3
star
31

unicode_scanner

Unicode-aware StringScanner implementation
Ruby
2
star
32

FART

Flight Assessment of Risk Tool
Swift
2
star
33

paperclip_duplicate_check

Adds to Paperclip the ability to skip uploading a file if it's the same as the file it's replacing
Ruby
2
star
34

TMInflector

English inflection library for Cocoa/Objective-C
Objective-C
2
star
35

sf50-pfpx-profiles

Cirrus SF50 VisionJet performance profiles for PFPX
2
star
36

quora_anthology

Generates a PDF e-book of your Quora answers.
Ruby
2
star
37

json_serialize

Adds JSON serialization to ActiveRecord models
Ruby
2
star
38

NTTRForeFlightContentPack

A ForeFlight content pack for the Nevada Test and Training Range (NTTR) (simulation use only)
2
star
39

SwitchColor

Switch Joy-Con colors
JavaScript
2
star
40

autumn-weather

IRC bot that displays the current weather
Ruby
2
star
41

also.fm

It IS actually at also.fm!
Ruby
2
star
42

find_or_create_on_scopes

find_or_create-type methods on ActiveRecord scopes
Ruby
2
star
43

VoiceRecognitionProfileGenerator

A script that generates both VAC and VoiceAttack profiles from a simple DSL
Swift
2
star
44

logten2foreflight

Converts LogTen Pro X logbooks into a CSV format importable to Foreflight Logbook
Swift
2
star
45

GarminACE

A Swift package that parses .ace files from the Garmin Aviation Checklist Editor program
Swift
2
star
46

rss-debrider

A utility that parses magnet links from an RSS feed, debrids them with Real-Debrid, and submits them to a Synology NAS for download.
Swift
1
star
47

Slackmoji

A simple Swift library that converts between emoji and Slack shortcodes
Swift
1
star
48

SwiftAirmen

Swift parser for the FAA airmen certification database.
Swift
1
star
49

hearts

Generate colorful emoji heart arrays from images
Swift
1
star
50

alumina

Ruby parser for various chemistry-related file formats
Ruby
1
star
51

budgeting

Simple budgeting app in Rails and Vue.js
Ruby
1
star
52

tim.codes

My homepage at https://tim.codes
TypeScript
1
star
53

OneMikeAlpha

A website for displaying and analyzing aircraft telemetry
Ruby
1
star
54

localized_each_validator

Simple EachValidator with localization support
Ruby
1
star
55

Aviation-Emoji

A collection of aviation-related emoji for Slack.
1
star
56

AvidyneR9ToGarmin

Converts Avidyne R9 data logs to Garmin CSV format
Swift
1
star
57

1MA-Avidyne-R9-Data-Loader

C-based data loader for Avidyne R9 Cirrus aircraft, for the OneMike Alpha website
C
1
star
58

closest-ndb

A website that shows you where the closest NDB is.
Vue
1
star
59

ranked

A website for ranking anything
Ruby
1
star
60

SF50-TOLD-Airports

Airport data for the SF50 TOLD iOS app
1
star