class Pandarus::Client

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

Public Class Methods

new(opts={}, target=nil) click to toggle source
# 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

Protected Instance Methods

method_missing(name, *args, &block) click to toggle source
# 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
required_params(params) click to toggle source
# File lib/pandarus/client.rb, line 54
def required_params(params)
  params.select{ |p| p.first == :req }.map{ |p| p.last }
end
target() click to toggle source
# File lib/pandarus/client.rb, line 58
def target
  @target ||= Pandarus::V1.new(@footrest_opts)
end