Module: HTTParty::Sober::ClassMethods

Defined in:
lib/httparty/sober.rb

Constant Summary collapse

@@cache_store =
nil
@@cache_options =
{}

Instance Method Summary collapse

Instance Method Details

#cache(cache_options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/httparty/sober.rb', line 11

def cache(cache_options={})
  @@cache_store = cache_options.delete(:store)
  APICache.store = @@cache_store if @@cache_store
  @@cache_options = cache_options
end

#cache!(cache_options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/httparty/sober.rb', line 17

def cache!(cache_options={})
  cache(cache_options)
  self.instance_eval do
    alias :get_without_caching :get
    alias :get :get_with_caching
  end
end

#get_with_caching(path, options = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/httparty/sober.rb', line 25

def get_with_caching(path, options={})
  cache_options = (@@cache_options || {}).merge(options[:cache] || {})
  APICache.get(path,cache_options) do 
    perform_request(Net::HTTP::Get, path, options)
  end
end