Friday, July 18, 2014

Dropbox API

I wanted to use Dropbox for the app I am currently working on. The general purpose of the app is to share (i.e. make public) or not to share (i.e. keep private) photos and videos, and the intended audience is social workers and speech language pathologists. So I needed a way to store the data somewhere. I decided to try Dropbox API, even though I already think that Dropbox may not be a good solution for my purposes, and I may want to use AWS instead. However, since the app is very much in early stages of development, experimenting with different APIs is a great idea.

I was particularly interested in how to obtain a shared link to an image, and there is a method called /shares. It takes path of a file as a parameter and returns a shortened url by default. According to Core API documentation, short_url parameter is optional and when it is set to false, the method returns a long url, which links directly to the preview page.


Ruby SDK didn't use to support this parameter up until a month ago. The method looked as follows (copied from their dropbox_sdk.rb):

def shares(path)
    response = @session.do_get "/shares/#{@root}#{format_path(path)}"
    Dropbox::parse_response(response)
end

It's been updated to the following:

def shares(path, short_url=true)
    response = @session.do_get "/shares/#{@root}#{format_path(path)}", 
                               {"short_url"=>short_url}
    Dropbox::parse_response(response)
end

I've noticed that neither RubyGems nor the official link to Ruby SDK carried an updated version as of today. Perhaps, there is some lengthy review/approval period? In the meantime, I've simply copied the updated method into my own SDK.

No comments :

Post a Comment