Module: HTTParty::Sober::ClassMethods
- Defined in:
- lib/httparty/sober.rb
Constant Summary collapse
- @@cache_store =
nil
- @@cache_options =
{}
Instance Method Summary collapse
- #cache(cache_options = {}) ⇒ Object
- #cache!(cache_options = {}) ⇒ Object
- #get_with_caching(path, options = {}) ⇒ Object
Instance Method Details
#cache(cache_options = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/httparty/sober.rb', line 12 def cache(={}) @@cache_store = .delete(:store) APICache.store = @@cache_store if @@cache_store @@cache_options = end |
#cache!(cache_options = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/httparty/sober.rb', line 18 def cache!(={}) cache() self.instance_eval do alias :get_without_caching :get alias :get :get_with_caching end end |
#get_with_caching(path, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/httparty/sober.rb', line 26 def get_with_caching(path, ={}) = (@@cache_options || {}).merge([:cache] || {}) query = [:query] ||= {} key = Digest::MD5.hexdigest("#{path.to_s}-#{query.collect{|e| e.join("=")}.join("&")}") APICache.get(key,) do perform_request(Net::HTTP::Get, path, ) end end |