Class: TheOneApi::ResourceWrapper
- Inherits:
-
Object
- Object
- TheOneApi::ResourceWrapper
- Defined in:
- lib/the_one_api/resource_wrapper.rb
Overview
A client for The One Api
Instance Method Summary collapse
-
#initialize(wrapped_resource, api_key) ⇒ ResourceWrapper
constructor
A new instance of ResourceWrapper.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(wrapped_resource, api_key) ⇒ ResourceWrapper
Returns a new instance of ResourceWrapper.
6 7 8 9 |
# File 'lib/the_one_api/resource_wrapper.rb', line 6 def initialize(wrapped_resource, api_key) @wrapped_resource = wrapped_resource @api_key = api_key end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/the_one_api/resource_wrapper.rb', line 11 def method_missing(method, *args, &block) super unless @wrapped_resource._calls.key?(method) # merge the api key in with the supplied # arguments so that the request can be authenticated args_with_api_key = if args[0].is_a?(Hash) (args[0]).merge({ api_key: @api_key }) elsif args[0] { id: args[0] }.merge({ api_key: @api_key }) else { api_key: @api_key } end @wrapped_resource.send(method, args_with_api_key, &block) end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
27 28 29 |
# File 'lib/the_one_api/resource_wrapper.rb', line 27 def respond_to_missing?(method, include_private = false) @wrapped_resource._calls.key?(method) || super end |