lib/chuckle/client.rb in chuckle-1.0.1 vs lib/chuckle/client.rb in chuckle-1.0.2
- old
+ new
@@ -5,11 +5,12 @@
include Chuckle::Options
attr_accessor :options, :cache
def initialize(options = {})
- self.options = DEFAULT_OPTIONS.merge(options)
+ self.options = DEFAULT_OPTIONS.dup
+ options.each { |k, v| self.options[k] = v if v }
self.cache = Cache.new(self)
sanity!
end
#
@@ -54,11 +55,18 @@
end
def curl(request)
vputs request.uri
rate_limit!(request)
- cache.set(request, Curl.new(request))
+
+ curl = Curl.new(request)
+ begin
+ curl.run
+ cache.set(request, curl)
+ ensure
+ curl.cleanup
+ end
end
def raise_errors(response)
# raise errors if necessary
error = if response.curl_exit_code
@@ -69,10 +77,10 @@
return if !error
if !cache_errors?
cache.clear(response.request)
end
- raise Error.new("Chuckle::Error, #{error}", response)
+ raise Error.new(error, response)
end
def vputs(s)
puts "chuckle: #{s}" if verbose?
end