lib/dropbox/api.rb in dropbox-1.0.0 vs lib/dropbox/api.rb in dropbox-1.1.0
- old
+ new
@@ -1,8 +1,7 @@
# Defines the Dropbox::API module.
-require "#{File.expand_path File.dirname(__FILE__)}/memoization"
require 'json'
require 'net/http/post/multipart'
module Dropbox
@@ -61,12 +60,12 @@
alias :file :entry
alias :directory :entry
alias :dir :entry
# Returns a +Struct+ with information about the user's account. See
- # http://developers.dropbox.com/python/base.html#account-info for more
- # information on the data returned.
+ # https://www.dropbox.com/developers/docs#account-info for more information
+ # on the data returned.
def account
get('account', 'info', :ssl => @ssl).to_struct_recursively
end
memoize :account
@@ -87,10 +86,57 @@
rest = Dropbox.check_path(path).split('/')
rest << { :ssl => @ssl }
api_body :get, 'files', root(options), *rest
#TODO streaming, range queries
end
+
+ # Downloads a minimized thumbnail for a file. Pass the path to the file,
+ # optionally the size of the thumbnail you want, and any additional options.
+ # See https://www.dropbox.com/developers/docs#thumbnails for a list of valid
+ # size specifiers.
+ #
+ # Returns the content of the thumbnail image as a +String+. The thumbnail
+ # data is in JPEG format. Returns +nil+ if the file does not have a
+ # thumbnail. You can check if a file has a thumbnail using the metadata
+ # method.
+ #
+ # Because of the way this API method works, if you pass in the name of a
+ # file that does not exist, you will not receive a 404, but instead just get
+ # +nil+.
+ #
+ # Options:
+ #
+ # +mode+:: Temporarily changes the API mode. See the MODES array.
+ #
+ # Examples:
+ #
+ # Get the thumbnail for an image (default thunmbnail size):
+ #
+ # session.thumbnail('my/image.jpg')
+ #
+ # Get the thumbnail for an image in the +medium+ size:
+ #
+ # session.thumbnail('my/image.jpg', 'medium')
+
+ def thumbnail(*args)
+ options = args.extract_options!
+ path = args.shift
+ size = args.shift
+ raise ArgumentError, "thumbnail takes a path, an optional size, and optional options" unless path.kind_of?(String) and (size.kind_of?(String) or size.nil?) and args.empty?
+
+ path.sub! /^\//, ''
+ rest = Dropbox.check_path(path).split('/')
+ rest << { :ssl => @ssl }
+ rest.last[:size] = size if size
+
+ begin
+ api_body :get, 'thumbnails', root(options), *rest
+ rescue Dropbox::UnsuccessfulResponseError => e
+ raise unless e.response.code.to_i == 404
+ return nil
+ end
+ end
# Uploads a file to a path relative to the configured mode's root. The
# +remote_path+ parameter is taken to be the path portion _only_; the name
# of the remote file will be identical to that of the local file. You can
# provide any of the following for the first parameter:
@@ -312,10 +358,10 @@
# If you pass a directory for +path+, the metadata will also contain a
# listing of the directory contents (unless the +suppress_list+ option is
# true).
#
# For information on the schema of the return struct, see the Dropbox API
- # at http://developers.dropbox.com/python/base.html#metadata
+ # at https://www.dropbox.com/developers/docs#metadata
#
# The +modified+ key will be converted into a +Time+ instance. The +is_dir+
# key will also be available as <tt>directory?</tt>.
#
# Options: