module HTTParty::Icebox

Public Class Methods

get(path, options={}) click to toggle source

Redefine original HTTParty get method to use cache

# File lib/p3-tvdb/httparty_icebox.rb, line 100
def self.get(path, options={})
  self.get_with_caching(path, options)
end
get_with_caching(path, options={}) click to toggle source

Get response from cache, if available

# File lib/p3-tvdb/httparty_icebox.rb, line 83
def self.get_with_caching(path, options={})
  key = path.clone
  key << options[:query].to_s if defined? options[:query]
  
  if cache.exists?(key) and not cache.stale?(key)
    Cache.logger.debug "CACHE -- GET #{path}#{options[:query]}"
    return cache.get(key)
  else
    Cache.logger.debug "/!\\ NETWORK -- GET #{path}#{options[:query]}"
    response = get_without_caching(path, options)
    cache.set(key, response) if response.code == 200
    return response
  end
end
get_without_caching(path, options={}) click to toggle source

Get reponse from network TODO: Why alias :new :old is not working here? Returns NoMethodError

# File lib/p3-tvdb/httparty_icebox.rb, line 77
def self.get_without_caching(path, options={})
  perform_request Net::HTTP::Get, path, options
end