• This repository has been archived on 19/Jun/2023
  • Stars
    star
    362
  • Rank 113,882 (Top 3 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated over 3 years ago

Reviews

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

Repository Details

Dropbox API Ruby Client

Dropbox::API - Dropbox Ruby API client

A Ruby client for the Dropbox REST API.

Goal:

To deliver a more Rubyesque experience when using the Dropbox API.

Current state:

First release, whole API covered.

Important!!!

From version 0.2.0, Dropbox::API::File#delete and Dropbox::API::Dir#delete are gone!!

The reason is that it's based on Hashie::Mash and was screwing Hash#delete.

It is replaced with Dropbox::API::File#destroy and Dropbox::API::Dir#destroy.

Installation

Dropbox::API is available on RubyGems, so:

gem install dropbox-api

Or in your Gemfile:

gem "dropbox-api"

Configuration

In order to use this client, you need to have an app created on https://www.dropbox.com/developers/apps.

Once you have it, put this configuration somewhere in your code, before you start working with the client.

Dropbox::API::Config.app_key    = YOUR_APP_KEY
Dropbox::API::Config.app_secret = YOUR_APP_SECRET
Dropbox::API::Config.mode       = "sandbox" # if you have a single-directory app
# Dropbox::API::Config.mode       = "dropbox" # if your app has access to the whole dropbox

Dropbox::API::Client

The client is the base for all communication with the API and wraps around almost all calls available in the API.

Web-based Authorization

In order to create a Dropbox::API::Client object, you need to have the configuration set up for OAuth. Second thing you need is to have the user authorize your app using OAuth. Here's a short intro on how to do this:

consumer = Dropbox::API::OAuth.consumer(:authorize)
request_token = consumer.get_request_token
# Store the token and secret so after redirecting we have the same request token
session[:token] = request_token.token
session[:token_secret] = request_token.secret
request_token.authorize_url(:oauth_callback => 'http://yoursite.com/callback')
# Here the user goes to Dropbox, authorizes the app and is redirected
# This would be typically run in a Rails controller
hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
request_token  = OAuth::RequestToken.from_hash(consumer, hash)
oauth_verifier = params[:oauth_verifier]
result = request_token.get_access_token(:oauth_verifier => oauth_verifier)

Now that you have the oauth token and secret, you can create a new instance of the Dropbox::API::Client, like this:

client = Dropbox::API::Client.new :token => result.token, :secret => result.secret

Rake-based authorization

Dropbox::API supplies you with a helper rake which will authorize a single client. This is useful for development and testing.

In order to have this rake available, put this on your Rakefile:

require "dropbox-api"
require "dropbox-api/tasks"
Dropbox::API::Tasks.install

You will notice that you have a new rake task - dropbox:authorize

When you call this Rake task, it will ask you to provide the app key and app secret. Afterwards it will present you with an authorize url on Dropbox.

Simply go to that url, authorize the app, then press enter in the console.

The rake task will output valid ruby code which you can use to create a client.

What differs this from the Dropbox Ruby SDK?

A few things:

  • It's using the ruby oauth gem, instead of reinventing the wheel and implementing OAuth communication
  • It treats files and directories as Ruby objects with appropriate classes, on which you can perform operations

Consider the following example which takes all files with names like 'test.txt' and copies them with a suffix '.old'

This is how it would look using the SDK:

# Because you need the session with the right access token, you need to create one instance per user
@session = DropboxSession.new(APP_TOKEN, APP_SECRET)
@session.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
@client = DropboxClient.new(@session, :app_folder)
# The result is a hash, so we need to call a method on the client, supplying the right key from the hash
@client.search('/', 'test.txt').each do |hash|
  @client.file_copy(hash['path'], hash['path'] + ".old")
end

With Dropbox::API, you can clean it up, first you put the app token and secret in a config or initializer file:

Dropbox::API::Config.app_key    = APP_TOKEN
Dropbox::API::Config.app_secret = APP_SECRET

And when you want to use it, just create a new client object with a specific access token and secret:

# The app token and secret are read from config, that's all you need to have a client ready for one user
@client = Dropbox::API::Client.new(:token  => ACCESS_TOKEN, :secret => ACCESS_SECRET)
# The file is a Dropbox::API::File object, so you can call methods on it!
@client.search('test.txt').each do |file|
  file.copy(file.path + ".old2")
end

What differs this from the dropbox gem?

Dropbox::API does not extend the Ruby primitives, like the dropbox gem:

https://github.com/RISCfuture/dropbox/tree/master/lib/dropbox/extensions

Dropbox::API::Client methods

Dropbox::API::Client#account

Returns a simple object with information about the account:

client.account # => #<Dropbox::API::Object>

For more info, see https://www.dropbox.com/developers/reference/api#account-info

Dropbox::API::Client#find

When provided a path, returns a single file or directory

client.find 'file.txt' # => #<Dropbox::API::File>

Dropbox::API::Client#destroy

Removes the file specified by path

Returns a Dropbox::API::File object of the deleted file

client.destroy 'file.txt' # => #<Dropbox::API::File>

Dropbox::API::Client#ls

When provided a path, returns a list of files or directories within that path

By default it's the root path:

client.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

But you can provide your own path:

client.ls 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

Dropbox::API::Client#mkdir

Creates a new directory and returns a Dropbox::API::Dir object

client.mkdir 'new_dir' # => #<Dropbox::API::Dir>

Dropbox::API::Client#upload

Stores a file with a provided body under a provided name and returns a Dropbox::API::File object

client.upload 'file.txt', 'file body' # => #<Dropbox::API::File>

Dropbox::API::Client#chunked_upload

Stores a file from a File object under a provided name and returns a Dropbox::API::File object. It should be used for larger files.

client.chunked_upload 'file.txt', File.open('file.txt') # => #<Dropbox::API::File>

Dropbox::API::Client#download

Downloads a file with a provided name and returns it's content

client.download 'file.txt' # => 'file body'

Dropbox::API::Client#search

When provided a pattern, returns a list of files or directories within that path

By default it searches the root path:

client.search 'pattern' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

However, you can specify your own path:

client.search 'pattern', :path => 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

Dropbox::API::Client#delta

Returns a cursor and a list of files that have changed since the cursor was generated.

delta = client.delta 'abc123'
delta.cursor # => 'def456'
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

When called without a cursor, it returns all the files.

delta = client.delta 'abc123'
delta.cursor # => 'abc123'
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

Optionally, you can set additional parameters, e.g. path_prefix. You can find all available parameters in the Dropbox API documentation.

delta = client.delta 'abc123', path_prefix: '/Path/To/My/Folder'
delta.cursor # => 'abc123'
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

Dropbox::API::File and Dropbox::API::Dir methods

These methods are shared by Dropbox::API::File and Dropbox::API::Dir

Dropbox::API::File#copy | Dropbox::API::Dir#copy

Copies a file/directory to a new specified filename

file.copy 'newfilename.txt' # => #<Dropbox::API::File>

Dropbox::API::File#move | Dropbox::API::Dir#move

Moves a file/directory to a new specified filename

file.move 'newfilename.txt' # => #<Dropbox::API::File>

Dropbox::API::File#destroy | Dropbox::API::Dir#destroy

Deletes a file/directory

file.destroy 'newfilename.txt' # => #<Dropbox::API::File>

Dropbox::API::File methods

Dropbox::API::File#revisions

Returns an Array of Dropbox::API::File objects with appropriate rev attribute

For more info, see https://www.dropbox.com/developers/reference/api#revisions

Dropbox::API::File#restore

Restores a file to a specific revision

For more info, see https://www.dropbox.com/developers/reference/api#restore

Dropbox::API::File#share_url

Returns the link to a file page in Dropbox

For more info, see https://www.dropbox.com/developers/reference/api#shares

Dropbox::API::File#direct_url

Returns the link to a file in Dropbox

For more info, see https://www.dropbox.com/developers/reference/api#media

Dropbox::API::File#thumbnail

Returns the thumbnail for an image

For more info, see https://www.dropbox.com/developers/reference/api#thumbnail

Dropbox::API::File#download

Downloads a file and returns it's content

file.download # => 'file body'

Dropbox::API::Dir methods

Dropbox::API::Dir#ls

Returns a list of files or directorys within that directory

dir.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]

Testing

In order to run tests, you need to have an application created and authorized. Put all tokens in spec/connection.yml and you're good to go.

Check out spec/connection.sample.yml for an example.

Releasing new version of gem

  1. Update version in lib/dropbox-api/version.rb and push to master
  2. Create new GitHub release with tag name starting with v and the version, for example v1.0.0
  3. Gem will be automatically built and pushed to rubygems.org with GitHub Action

Copyright and license

Copyright 2011 Zendesk

Licensed under the Apache License, Version 2.0

More Repositories

1

android-floating-action-button

Floating Action Button for Android based on Material Design specification
Java
6,374
star
2

maxwell

Maxwell's daemon, a mysql-to-json kafka producer
Java
3,891
star
3

cross-storage

Cross domain local storage, with permissions
JavaScript
2,190
star
4

samson

Web interface for deployments, with plugin architecture and kubernetes support
Ruby
1,443
star
5

ruby-kafka

A Ruby client library for Apache Kafka
Ruby
1,264
star
6

helm-secrets

DEPRECATED A helm plugin that help manage secrets with Git workflow and store them anywhere
Shell
1,159
star
7

curly

The Curly template language allows separating your logic from the structure of your HTML templates.
Ruby
592
star
8

biz

Time calculations using business hours.
Ruby
486
star
9

racecar

Racecar: a simple framework for Kafka consumers in Ruby
Ruby
475
star
10

zendesk_api_client_rb

Official Ruby Zendesk API Client
Ruby
382
star
11

zendesk_api_client_php

Official Zendesk API v2 client library for PHP
PHP
332
star
12

stronger_parameters

Type checking and type casting of parameters for Action Pack
Ruby
297
star
13

active_record_shards

Support for sharded databases and replicas for ActiveRecord
Ruby
247
star
14

delivery_boy

A simple way to publish messages to Kafka from Ruby applications
Ruby
236
star
15

android-db-commons

Some common utilities for ContentProvider/ContentResolver/Cursor and other db-related android stuff
Java
223
star
16

radar

High level API and backend for writing web apps that use push messaging
JavaScript
221
star
17

sunshine-conversations-web

The Smooch Web SDK will add live web messaging to your website or web app.
212
star
18

demo_apps

HTML
179
star
19

arturo

Feature Sliders for Rails
Ruby
174
star
20

belvedere

An image picker library for Android
Java
146
star
21

zendesk_jwt_sso_examples

Examples using JWT for Zendesk SSO
Ruby
142
star
22

sunshine-conversations-ios

Smooch
Objective-C
122
star
23

laika

Log, test, intercept and modify Apollo Client's operations
TypeScript
120
star
24

prop

Puts a cork in their requests
Ruby
117
star
25

zendesk_sdk_ios

Zendesk Mobile SDK for iOS
Objective-C
117
star
26

zopim-chat-web-sdk-sample-app

Zendesk Chat Web SDK sample app developed using React
JavaScript
98
star
27

copenhagen_theme

The default theme for Zendesk Guide
Handlebars
95
star
28

app_scaffold

A scaffold for developers to build ZAF v2 apps
JavaScript
90
star
29

node-publisher

A zero-configuration release automation tool for Node packages inspired by create-react-app and Travis CI.
JavaScript
76
star
30

zendesk_apps_tools

Ruby
75
star
31

zendesk_app_framework_sdk

The Zendesk App Framework (ZAF) SDK is a JavaScript library that simplifies cross-frame communication between iframed apps and the Zendesk App Framework
JavaScript
71
star
32

ios_sdk_demo_apps

This repository contains sample iOS code and applications which use our SDKs
Swift
64
star
33

zendesk_sdk_chat_ios

Mobile Chat SDK for iOS
Objective-C
63
star
34

kamcaptcha

A captcha plugin for Rails
Ruby
63
star
35

linksf

A mobile website to connect those in need in to services that can help them
JavaScript
62
star
36

sdk_demo_app_android

This is Remember The Date, an Android demo app for our Mobile SDK. All docs available on developer.zendesk.com
Java
61
star
37

zcli

A command-line tool for Zendesk
TypeScript
56
star
38

go-httpclerk

A simple HTTP request/response logger for Go supporting multiple formatters.
Go
51
star
39

property_sets

A way to store attributes in a side table.
Ruby
51
star
40

android-schema-utils

Android library for simplifying database schema and migrations management.
Java
48
star
41

android_sdk_demo_apps

This repository contains sample android code and applications which use our SDKs
Java
46
star
42

statsd-logger

StatsD + Datadog APM logging server for development - standalone or embedded
Go
44
star
43

sunshine-conversations-android

Smooch Android SDK
42
star
44

support_sdk_ios

Zendesk Support SDK for iOS
Objective-C
37
star
45

react-native-sunshine-conversations

React Native wrapper for Smooch.io
Java
36
star
46

docker-logs-tail

Docker Logs Tail simultaneously tails logs for all running Docker containers, interleaving them in the command line output
JavaScript
35
star
47

call_center

Ruby
34
star
48

curlybars

Handlebars.js compatible templating library in Ruby
Ruby
34
star
49

kasket

A caching layer for ActiveRecord. Puts a cap on your queries!
Ruby
33
star
50

ruby_memprofiler_pprof

Experimental memory profiler for Ruby that emits pprof files.
C
33
star
51

method_struct

Ruby
33
star
52

samlr

Clean room implementation of SAML for Ruby
Ruby
31
star
53

min-tfs-client

A lightweight python gRPC client to communicate with TensorFlow Serving
C++
31
star
54

sdk_demo_app_ios

This is Remember The Date, an iOS demo app for our Mobile SDK. All docs available on developer.zendesk.com
Objective-C
31
star
55

classic_asp_jwt

A JWT implementation in Classic ASP
ASP
29
star
56

basecrm-ruby

Base CRM API Client
Ruby
29
star
57

volunteer_portal

An event calendar focused on tracking and reporting volunteering opportunities
JavaScript
28
star
58

ultragrep

the grep that greps the hardest.
C
28
star
59

chariot-tooltips

A javascript library for creating on screen step by step tutorials.
JavaScript
26
star
60

clj-headlights

Clojure on Beam
Clojure
26
star
61

sunshine-conversations-javascript

Javascript API for Sunshine Conversations
JavaScript
26
star
62

android-autoprovider

Utility for creating ContentProviders without boilerplate and with heavy customization options.
Java
25
star
63

basecrm-php

Base CRM API client, PHP edition
PHP
23
star
64

migration_tools

Rake tasks for Rails that add groups to migrations
Ruby
23
star
65

large_object_store

Store large objects in memcache or others by slicing them.
Ruby
22
star
66

term-check

A GitHub app which runs checks for flagged terminology in GitHub repos
Go
22
star
67

basecrm-python

BaseCRM API Client for Python
Python
22
star
68

sdk_unity_plugin

This repository contains a unity plugin which wraps the Zendesk support SDKs
Objective-C
22
star
69

jazon

Test assertions on JSONs have never been easier
Java
21
star
70

ipcluster

Node.js master/worker clustering module for sticky session load balancing using IPTABLES
JavaScript
21
star
71

sunshine-conversations-python

Smooch API Library for Python
Python
21
star
72

cloudwatch-logger

Connects standard input to Amazon CloudWatch Logs
Go
20
star
73

forger

Android library for populating the ContentProvider with test data.
Java
19
star
74

radar_client

High level API and backend for writing web apps that use push messaging
JavaScript
19
star
75

double_doc

Write documentation with your code, to keep them in sync, ideal for public API docs.
Ruby
18
star
76

pakkr

Python pipeline utility library
Python
18
star
77

chat_sdk_ios

Zendesk Chat SDK
Objective-C
18
star
78

goship

Utility that helps find, connect and copy to particular cloud resources using configured providers
Go
18
star
79

url_builder_app

A Zendesk App to help you generate links for agents.
JavaScript
18
star
80

sunshine-conversations-api-quickstart-example

Sample code to get started with the Smooch REST APIs
JavaScript
17
star
81

zendesk_apps_support

Ruby
17
star
82

sunshine-conversations-desk

A sample business system built with Meteor and the Smooch API
CSS
17
star
83

apt-s3

apt method for private S3 buckets
Go
17
star
84

api_client

HTTP API Client Builder
Ruby
16
star
85

iron_bank

An opinionated Ruby interface to the Zuora REST API
Ruby
15
star
86

active_record_host_pool

Connect to multiple databases using one ActiveRecord connection
Ruby
15
star
87

private_gem

Keeps your private gems private
Ruby
15
star
88

sdk_messaging_ios

The Zendesk Messaging SDK
Objective-C
14
star
89

rate_my_app_ios

An open source version of the Rate My App feature from 1.x versions of the Support SDK.
Swift
14
star
90

input_sanitizer

A gem to sanitize hash of incoming data
Ruby
14
star
91

sunshine-conversations-conversation-extension-examples

A series of examples using Smooch conversation extensions
HTML
14
star
92

scala-flow

A lightweight library intended to make developing Google DataFlow jobs in Scala easier.
Scala
14
star
93

punchabunch

Punchabunch: A highly concurrent, easily configurable SSH local-forwarding proxy
Go
14
star
94

zendesk-jira-plugin

Java
13
star
95

sunshine-conversations-ruby

Smooch API Library for Ruby
Ruby
13
star
96

samson_secret_puller

kubernetes sidecar and app to publish secrets to a containerized app.
Ruby
13
star
97

sqlitemaster

Android library for getting existing db schema information from sqlite_master table.
Java
13
star
98

ticket_sharing

Ticket Sharing
Ruby
13
star
99

sunshine-conversations-wordpress

PHP
13
star
100

sunshine-conversations-api-spec

Sunshine Conversations OpenAPI Specification for v2+
12
star