lib/amee/session.rb in hookercookerman-amee-0.0.4 vs lib/amee/session.rb in hookercookerman-amee-0.0.5
- old
+ new
@@ -63,20 +63,20 @@
# @param [Hash] options
# @param [Boolean] use_auth_token NOTE not using this right now
def api_call_without_logging(method, parser_name, path, options, use_auth_token =true, &proc)
result = service.send(method, parser_name, path, options)
result = yield result if block_given?
- store_resource(path,result, options[:cache]||{}) if method == :get && caching?
+ store_resource(path,result, options||{}) if method == :get && caching?
result
end
# this over long ie bad method is to either get the cache for a api call
# or actually call the amee api; if the session has expired we will try
# to get a new one
def api_call(method, parser_name, path, options ={}, use_auth_token =true, &proc)
- if (cache = @cache[path]) && caching?
+ if (cache = @cache[cache_key(path, options[:query] || {})]) && caching?
return cache
else
attempts = 0
begin
if Amee::Config[:logging]
@@ -212,11 +212,18 @@
api_call(:get, "raw", path)
end
# @param [String] path the path of the resource
# @param [Hash] cache_options this is the cache options
- def store_resource(path, result, cache_options = {})
- @cache.store(path, result, :expires_in => cache_options[:expires_in] || Amee::Config[:expires_in])
+ def store_resource(path, result, options = {})
+ key = cache_key(path, options[:query] ||{})
+ cache_options = options[:cache] || {}
+ @cache.store(key, result, :expires_in => cache_options[:expires_in] || Amee::Config[:expires_in])
+ end
+
+ protected
+ def cache_key(path, params = {})
+ path + params.map { |key,value| "#{key}=#{value}" }.join('/')
end
end
end
\ No newline at end of file