lib/dbox/api.rb in dbox-0.4.4 vs lib/dbox/api.rb in dbox-0.5.0
- old
+ new
@@ -28,16 +28,22 @@
api = new()
api.connect
api
end
+ attr_reader :client
+
# IMPORTANT: API.new is private. Please use API.authorize or API.connect as the entry point.
private_class_method :new
def initialize
@conf = self.class.conf
end
+ def initialize_copy(other)
+ @client = other.client.clone()
+ end
+
def connect
auth_key = ENV["DROPBOX_AUTH_KEY"]
auth_secret = ENV["DROPBOX_AUTH_SECRET"]
raise(ConfigurationError, "Please set the DROPBOX_AUTH_KEY environment variable to an authenticated Dropbox session key") unless auth_key
@@ -50,30 +56,34 @@
def run(path)
begin
res = yield
case res
when Hash
- res
+ HashWithIndifferentAccess.new(res)
when String
res
when Net::HTTPNotFound
raise RemoteMissing, "#{path} does not exist on Dropbox"
when Net::HTTPForbidden
raise RequestDenied, "Operation on #{path} denied"
+ when Net::HTTPNotModified
+ :not_modified
+ when true
+ true
else
raise RuntimeError, "Unexpected result: #{res.inspect}"
end
rescue DropboxError => e
log.debug e.inspect
raise ServerError, "Server error -- might be a hiccup, please try your request again (#{e.message})"
end
end
- def metadata(path = "/")
+ def metadata(path = "/", hash = nil)
log.debug "Fetching metadata for #{path}"
run(path) do
- res = @client.metadata(@conf["root"], escape_path(path))
+ res = @client.metadata(@conf["root"], escape_path(path), 10000, hash)
log.debug res.inspect
res
end
end
@@ -94,13 +104,13 @@
run(path) do
@client.file_delete(@conf["root"], path)
end
end
- def get_file(path)
+ def get_file(path, output_file_obj)
log.info "Downloading #{path}"
run(path) do
- @client.get_file(@conf["root"], escape_path(path))
+ @client.get_file(@conf["root"], escape_path(path), output_file_obj)
end
end
def put_file(path, file_obj)
log.info "Uploading #{path}"