lib/filezor/client.rb in filezor-1.3.2 vs lib/filezor/client.rb in filezor-1.3.3
- old
+ new
@@ -9,13 +9,21 @@
class Unauthorized < RuntimeError; end
class InvalidArgument < RuntimeError; end
attr_reader :options
+ def self.last_exception
+ @e
+ end
+
+ def self.last_exception=(e)
+ @e = e
+ end
+
def initialize(host, port, password, options = {})
@root = "http://admin:#{password}@#{host}:#{port}"
- @options ||= options
+ @options ||= stringify_keys(options)
@options.update JSON.parse(post("info", options.to_json, "/"))
end
# This method acts like an rsync --delete. It deletes all files in the root,
# and then puts the new files in. TODO: make atomic
@@ -87,20 +95,30 @@
private
def _get(*args)
puts args.inspect if ENV["FILEZOR_DEBUG"]
RestClient.get(*args)
+ rescue => e
+ self.class.last_exception = e
+ raise
end
def _post(*args)
puts args.inspect if ENV["FILEZOR_DEBUG"]
RestClient.post(*args)
+ rescue => e
+ self.class.last_exception = e
+ raise
end
def test(*files)
files.flatten.each do |file|
unless file.is_a?(Filezor::File)
raise InvalidArgument.new(file.inspect)
end
end
+ end
+
+ def stringify_keys(hash)
+ hash.inject({}) {|memo, (k, v)| memo.update k.to_s => v }
end
end
\ No newline at end of file