module OpenTok::TokenGenerator::ClassMethods

Public Instance Methods

arg_lambdas() click to toggle source

@private For internal use by the SDK.

# File lib/opentok/token_generator.rb, line 41
def arg_lambdas
  @arg_lambdas
end
generate_token() click to toggle source

Generates a token

# File lib/opentok/token_generator.rb, line 46
def generate_token
  TokenGenerator::GENERATE_TOKEN_LAMBDA
end
generates_tokens(arg_lambdas={}) click to toggle source

@private arguments the method we should generate will need (in order):

  • api_key (required - if no lambda assigned, part of method sig)

  • api_secret (required - if no lambda assigned, part of method sig)

  • session_id (required - if no lambda assigned, part of method sig)

  • token_opts (optional - part of method sig)

arg_lambdas is a hash of keys which are the above args and values are lambdas that all have the signature ->(instance)

# File lib/opentok/token_generator.rb, line 27
def generates_tokens(arg_lambdas={})
  @arg_lambdas = arg_lambdas
  define_method(:generate_token) do |*args|
    # puts "generate_something is being called on #{self}. set up with #{method_opts.inspect}"
    dynamic_args = [ :api_key, :api_secret, :session_id, :token_opts ].map do |arg|
      self.class.arg_lambdas[arg].call(self) if self.class.arg_lambdas[arg]
    end
    dynamic_args.compact!
    args = args.first(4-dynamic_args.length)
    self.class.generate_token.call(*dynamic_args, *args)
  end
end