module RiotAPI::API

Public Instance Methods

call(strategy, action, *args) click to toggle source

call strategy with action and arguments

# File lib/riot_api/api.rb, line 37
def call(strategy, action, *args)
  stra = instance_variable_get :"@#{strategy}" 
  if stra.nil?
    raise StrategyNotRegistered
  else
    stra.send action, args
  end
end
key() click to toggle source
# File lib/riot_api/api.rb, line 8
def key
  @key
end
register(strategy) click to toggle source

register a strategy

# File lib/riot_api/api.rb, line 26
def register(strategy)
  stra_sym = :"@#{strategy}" 
  stra = instance_variable_get stra_sym
  if stra.nil?
    strategy_class = eval("RiotAPI::Strategies::#{strategy.camel_case}")
    instance_variable_set stra_sym, strategy_class.new.extend(RiotAPI::Requester)
    define_method(strategy) { instance_variable_get stra_sym }
  end
end
register_all() click to toggle source

register all strategies using the files in strategies folder

# File lib/riot_api/api.rb, line 17
def register_all
  dirs = Dir.entries File.join(File.expand_path(File.dirname(__FILE__)), "strategies") 
  dirs.delete(".")
  dirs.delete("..")
  dirs.map! { |dir| dir.sub(".rb", "") }
  dirs.each { |stra| register(stra) }
end
setup(key) click to toggle source
# File lib/riot_api/api.rb, line 12
def setup(key) 
  @key = key
end