Class: Pandarus::Client
- Inherits:
-
Object
- Object
- Pandarus::Client
- Defined in:
- lib/pandarus/client.rb
Overview
Client is a class just like Pandarus::V1, but you only need to pass the account_id in once.
Example:
client = Pandarus::Client.new(
:account_id => 1,
:prefix => "http://canvas.instructure.com/api",
:token => "1~z8d91308...etc")
Now, instead of passing in account_id to each method, just skip it:
client.list_available_reports
Instance Method Summary collapse
-
#initialize(opts = {}, target = nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts = {}, target = nil) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 |
# File 'lib/pandarus/client.rb', line 20 def initialize(opts={}, target=nil) footrest_keys = [:token, :prefix, :logging, :logger] @footrest_opts = opts.slice(*footrest_keys) # Prepare defaults @overridden_params = opts @overridden_params.delete_if{ |k,v| footrest_keys.include?(k.to_sym) } @target = target end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pandarus/client.rb', line 31 def method_missing(name, *args, &block) params = target.method(name).parameters if params.empty? # no params, nothing to modify, just pass the block target.send(name, *args, &block) else # Fill in any args that are overridden, and use the others as-is overridden_args = required_params(params).map do |param_name| if @overridden_params.keys.include?(param_name) @overridden_params[param_name] else args.shift end end # Tack on optional args, if any overridden_args += args if args.size > 0 # Send our method + args to the Pandarus::V1 target of this proxy object target.send(name, *overridden_args, &block) end end |