Module: RiotAPI::API

Extended by:
API
Included in:
API
Defined in:
lib/riot_api/api.rb

Defined Under Namespace

Classes: StrategyNotRegistered

Instance Method Summary collapse

Instance Method Details

#call(strategy, action, *args) ⇒ Object

call strategy with action and arguments



37
38
39
40
41
42
43
44
# 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

#keyObject



8
9
10
# File 'lib/riot_api/api.rb', line 8

def key
  @key
end

#register(strategy) ⇒ Object

register a strategy



26
27
28
29
30
31
32
33
34
# 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_allObject

register all strategies using the files in strategies folder



17
18
19
20
21
22
23
# 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) ⇒ Object



12
13
14
# File 'lib/riot_api/api.rb', line 12

def setup(key) 
  @key = key
end