Clojure bindings to the Dropbox API
Clojure
Pull request Compare This branch is 1 commit ahead of whacked:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/clj_dropbox
.gitignore
LICENSE
README.markdown
project.clj

README.markdown

Clojure bindings to Dropbox API

clj-dropbox provides clojure bindings to the Dropbox API. In order to use this library, you need to at least setup as a Dropbox developer and get an OAuth conumser key. Instructions can be found here.

The library depends upon `clj-oauth' version 1.2.1 and which is in clojars.org.

Building

lein jar

Example

(require '[clj-dropbox.client :as dropbox])

; First you make a `consumer' which represents your 
; Dropbox  credientials you need to interact with Dropbox's OAuth. 
(def consumer (dropbox/new-consumer "my-developer-key" "my-developer-secret"))

; You need to do the OAuth dance in order
; to get the user-key and user-secret. You
; should persistently store these. 
(let [[authorization-url request-callback] 
         (dropbox/request-user-authorization consumer my-callback-url)]
  ; User grants you access
  (println "Dear user authorize me at " authorization-url)
  ; After this is done and my-callback-url is pinged 
  ; (you can leave my-callback-url as  nil)
  (let [[user-key user-secret] (request-callback)]
    (println "I have user token info!")))  

; Once you have user-key and user-secret, make a client 
(def client (dropbox/new-user-client consumer user-key user-secret))

; Now you can do the fun stuff (see src/clj-dropbox/client.clj)

; Upload local file to dropbox
(dropbox/upload-file client "/path/to-local-file.txt" "dropbox-dir/")

; List files in root dropbox directory
; returns seq of file meta-data 
(dropbox/list-files client "")

; Get the contents of a file as a string
(dropbox/get-file client "tmp/my-great-idea.txt")

; If you want to do several operations with the same user
; on the same thread, you can save yourself the trouble
; of using the client argument everywhere
(dropbox/with-user (new-user-client consumer user-key user-secret)
  (doseq [[i f] (indexed (dropbox/list-files "")) 
        :when (= (-> f :path (.endsWith ".txt")))]
    (dropbox/copy-file (:path f) (str "my-text-files/txt-file-" i))))

Author

Aria Haghighi (aria42@gmail.com)

My Website

Support

Email author with any issues.

Todo

  • Make SSL an option
  • Support creating an account
  • Support the OAuth-bypass Dropbox allows. Its dangerous though!
  • Fix any bugs I'm sure are in this.

License

Copyright (C) 2010 Aria Haghighi

Distributed under the Eclipse Public License, the same as Clojure uses. See the file License.