Class: BananaPeels::API::Proxy
- Inherits:
-
Object
- Object
- BananaPeels::API::Proxy
- Defined in:
- lib/banana_peels/api.rb
Instance Method Summary collapse
-
#initialize(api_key, mod) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(api_key, mod) ⇒ Proxy
Returns a new instance of Proxy.
97 98 99 100 |
# File 'lib/banana_peels/api.rb', line 97 def initialize(api_key, mod) @api_key = api_key @mod = mod end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/banana_peels/api.rb', line 102 def method_missing(method, *args) if API.cache? cache_keys = [ @api_key, @mod.to_s, method.to_s ] cache_keys.concat(args) cache_key = cache_keys.to_json cache_val = API.cache_get(cache_key) return cache_val if cache_val end cache_val = Mailchimp::API.new(@api_key).__send__(@mod).__send__(method, *args) API.cache_set(cache_key, cache_val) if API.cache? cache_val end |