lib/dropbox/api.rb in dropbox-1.1.0 vs lib/dropbox/api.rb in dropbox-1.1.1
- old
+ new
@@ -80,11 +80,11 @@
# Options:
#
# +mode+:: Temporarily changes the API mode. See the MODES array.
def download(path, options={})
- path.sub! /^\//, ''
+ path = path.sub(/^\//, '')
rest = Dropbox.check_path(path).split('/')
rest << { :ssl => @ssl }
api_body :get, 'files', root(options), *rest
#TODO streaming, range queries
end
@@ -121,11 +121,11 @@
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! /^\//, ''
+ path = path.sub(/^\//, '')
rest = Dropbox.check_path(path).split('/')
rest << { :ssl => @ssl }
rest.last[:size] = size if size
begin
@@ -165,11 +165,11 @@
local_path = local_file
else
raise ArgumentError, "local_file must be a File or file path"
end
- remote_path.sub! /^\//, ''
+ remote_path = remote_path.sub(/^\//, '')
remote_path = Dropbox.check_path(remote_path).split('/')
remote_path << { :ssl => @ssl }
url = Dropbox.api_url('files', root(options), *remote_path)
uri = URI.parse(url)
@@ -215,12 +215,12 @@
# +mode+:: Temporarily changes the API mode. See the MODES array.
#
# TODO The API documentation says this method returns 404/403 if the source or target is invalid, but it actually returns 5xx.
def copy(source, target, options={})
- source.sub! /^\//, ''
- target.sub! /^\//, ''
+ source = source.sub(/^\//, '')
+ target = target.sub(/^\//, '')
target << File.basename(source) if target.ends_with?('/')
begin
parse_metadata(post('fileops', 'copy', :from_path => Dropbox.check_path(source), :to_path => Dropbox.check_path(target), :root => root(options), :ssl => @ssl)).to_struct_recursively
rescue UnsuccessfulResponseError => error
raise FileNotFoundError.new(source) if error.response.kind_of?(Net::HTTPNotFound)
@@ -241,11 +241,11 @@
# +mode+:: Temporarily changes the API mode. See the MODES array.
#
# TODO The API documentation says this method returns 403 if the path already exists, but it actually appends " (1)" to the end of the name and returns 200.
def create_folder(path, options={})
- path.sub! /^\//, ''
+ path = path.sub(/^\//, '')
path.sub! /\/$/, ''
begin
parse_metadata(post('fileops', 'create_folder', :path => Dropbox.check_path(path), :root => root(options), :ssl => @ssl)).to_struct_recursively
rescue UnsuccessfulResponseError => error
raise FileExistsError.new(path) if error.response.kind_of?(Net::HTTPForbidden)
@@ -264,11 +264,11 @@
# +mode+:: Temporarily changes the API mode. See the MODES array.
#
# TODO The API documentation says this method returns 404 if the path does not exist, but it actually returns 5xx.
def delete(path, options={})
- path.sub! /^\//, ''
+ path = path.sub(/^\//, '')
path.sub! /\/$/, ''
begin
api_response(:post, 'fileops', 'delete', :path => Dropbox.check_path(path), :root => root(options), :ssl => @ssl)
rescue UnsuccessfulResponseError => error
raise FileNotFoundError.new(path) if error.response.kind_of?(Net::HTTPNotFound)
@@ -294,12 +294,12 @@
# +mode+:: Temporarily changes the API mode. See the MODES array.
#
# TODO The API documentation says this method returns 404/403 if the source or target is invalid, but it actually returns 5xx.
def move(source, target, options={})
- source.sub! /^\//, ''
- target.sub! /^\//, ''
+ source = source.sub(/^\//, '')
+ target = target.sub(/^\//, '')
target << File.basename(source) if target.ends_with?('/')
begin
parse_metadata(post('fileops', 'move', :from_path => Dropbox.check_path(source), :to_path => Dropbox.check_path(target), :root => root(options), :ssl => @ssl)).to_struct_recursively
rescue UnsuccessfulResponseError => error
raise FileNotFoundError.new(source) if error.response.kind_of?(Net::HTTPNotFound)
@@ -320,11 +320,11 @@
#
# session.move 'path/to/file', 'path/to/new_name'
def rename(path, new_name, options={})
raise ArgumentError, "Names cannot have slashes in them" if new_name.include?('/')
- path.sub! /\/$/, ''
+ path = path.sub(/\/$/, '')
destination = path.split('/')
destination[destination.size - 1] = new_name
destination = destination.join('/')
move path, destination, options
end
@@ -337,11 +337,11 @@
# Options:
#
# +mode+:: Temporarily changes the API mode. See the MODES array.
def link(path, options={})
- path.sub! /^\//, ''
+ path = path.sub(/^\//, '')
begin
rest = Dropbox.check_path(path).split('/')
rest << { :ssl => @ssl }
api_response(:get, 'links', root(options), *rest)
rescue UnsuccessfulResponseError => error
@@ -375,10 +375,10 @@
# +mode+:: Temporarily changes the API mode. See the MODES array.
#
# TODO hash option seems to return HTTPBadRequest for now
def metadata(path, options={})
- path.sub! /^\//, ''
+ path = path.sub(/^\//, '')
args = [
'metadata',
root(options)
]
args += Dropbox.check_path(path).split('/')