lib/satisfaction/loader.rb in ruby-satisfaction-0.1.0 vs lib/satisfaction/loader.rb in ruby-satisfaction-0.2.0

- old
+ new

@@ -10,10 +10,14 @@ attr_reader :cache attr_reader :options def initialize(options={}) @options = options.reverse_merge({:cache => :hash}) + reset_cache + end + + def reset_cache @cache = case @options[:cache] when :hash then HashCache.new when :memcache then MemcacheCache.new(@options[:memcache] || {}) else raise ArgumentError, "Invalid cache spec: #{@options[:cache]}" @@ -33,17 +37,23 @@ add_authentication(request, options) response = execute(http, request) case response when Net::HTTPNotModified - return cache_record.body + return [:ok, cache_record.body] when Net::HTTPSuccess cache.put(uri, response) - response.body + [:ok, response.body] when Net::HTTPMovedPermanently limit = options[:redirect_limit] || 3 raise ArgumentError, "Too many redirects" unless limit > 0 #TODO: what is a better error here? get(response['location'], options.merge(:redirect_limit => limit - 1)) + when Net::HTTPBadRequest + [:bad_request, response.body] + when Net::HTTPForbidden + [:forbidden, response.body] + when Net::HTTPUnauthorized + [:unauthorized, response.body] else raise "Explode: #{response.to_yaml}" end end