Module: LeagueApi

Extended by:
LeagueApi
Included in:
LeagueApi
Defined in:
lib/league_api.rb,
lib/league_api/game.rb,
lib/league_api/team.rb,
lib/league_api/util.rb,
lib/league_api/stats.rb,
lib/league_api/league.rb,
lib/league_api/static.rb,
lib/league_api/champion.rb,
lib/league_api/summoner.rb,
lib/league_api/current_game.rb,
lib/league_api/featured_games.rb

Defined Under Namespace

Classes: Champion, CurrentGame, FeaturedGames, Game, League, Static, Stats, Summoner, Team, Util

Instance Method Summary collapse

Instance Method Details

#available_requestsObject

Display all available Requests for all API classes



34
35
36
37
38
39
40
41
42
# File 'lib/league_api.rb', line 34

def available_requests
  requests = {}
  requests[LeagueApi] = self.instance_methods.map &:to_s

  self.constants.each do |i|
    requests[eval(i.to_s)] = eval(i.to_s).requests
  end
  requests
end

#before(*methods) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/league_api.rb', line 79

def before(*methods)
  methods.each do |name|
    m = instance_method(name)
    define_method(name) do |*args, &block|
      yield
      m.bind(self).(*args, &block)
    end
  end
end

#get_champion_namesObject

Returns an array of champion names



45
46
47
# File 'lib/league_api.rb', line 45

def get_champion_names
  Static.get_champion_list.keys
end

#get_item_namesObject

Returns an array of item names



50
51
52
53
54
55
56
# File 'lib/league_api.rb', line 50

def get_item_names
  items = []
  Static.get_item_list.values.each do |f|
    items << f["name"]
  end
  items
end

#get_last_champion_played(id, region = nil) ⇒ Object

Return a String for the last champion played



69
70
71
72
# File 'lib/league_api.rb', line 69

def get_last_champion_played(id, region=nil)
  champ_id = Game.recent_games(id, region).first["championId"]
  Static.get_inverted_champion_list[champ_id]
end

#get_last_game_played(id, region = nil) ⇒ Object

Return unformatted JSON of the last game played



64
65
66
# File 'lib/league_api.rb', line 64

def get_last_game_played(id, region=nil)
  Game.recent_games(id, region).first
end

#get_summoner_id(str, region = nil) ⇒ Object

Return player id given the summoner name



59
60
61
# File 'lib/league_api.rb', line 59

def get_summoner_id(str, region=nil)
  Summoner.find_by_name(str, region)["id"]
end

#get_time_of_last_game(id, region = nil) ⇒ Object

Return the Time for the last played game



75
76
77
# File 'lib/league_api.rb', line 75

def get_time_of_last_game(id, region=nil)
  Time.at( Game.recent_games(id, region).first["createDate"] / 1000 )
end

#make_request(base, modifier = nil, params = nil, region = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/league_api.rb', line 22

def make_request(base, modifier=nil, params=nil, region=nil)
  region = @default_region if region.nil?
  base = change_base(base, region)

  url = base + modifier
  url << add_query_string(params)

  uri = URI.parse(url)
  JSON.parse(uri.read)
end