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
Defined Under Namespace
Classes: Champion, Game, League, Static, Stats, Summoner, Team, Util
Constant Summary collapse
- @@default_region =
"na"
Instance Method Summary collapse
-
#available_requests ⇒ Object
Display all available Requests for all API classes.
- #change_base(url, region) ⇒ Object
- #change_region(region) ⇒ Object
- #default_region ⇒ Object
-
#get_champion_names ⇒ Object
Returns an array of champion names.
-
#get_item_names ⇒ Object
Returns an array of item names.
-
#get_last_champion_played(id, region = nil) ⇒ Object
Return a String for the last champion played.
-
#get_last_game_played(id, region = nil) ⇒ Object
Return unformatted JSON of the last game played.
- #get_region(region) ⇒ Object
-
#get_summoner_id(str, region = nil) ⇒ Object
Return player id given the summoner name.
-
#get_time_of_last_game(id, region = nil) ⇒ Object
Return the Time for the last played game.
- #make_request(base, modifier = nil, params = nil, region = nil) ⇒ Object
- #set_region(name) ⇒ Object
Instance Method Details
#available_requests ⇒ Object
Display all available Requests for all API classes
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/league_api.rb', line 90 def available_requests c = self.constants requests = {} requests[LeagueApi] = self.instance_methods.map &:to_s c.each do |i| requests[eval(i.to_s)] = eval(i.to_s).requests end requests end |
#change_base(url, region) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/league_api.rb', line 64 def change_base(url, region) case region when "euw" url.gsub("na.api.pvp.net","euw.api.pvp.net").gsub("na","euw") when "br" url.gsub("na.api.pvp.net","br.api.pvp.net").gsub("na","br") when "eune" url.gsub("na.api.pvp.net","eune.api.pvp.net").gsub("na","eune") when "kr" url.gsub("na.api.pvp.net","kr.api.pvp.net").gsub("na","kr") when "las" url.gsub("na.api.pvp.net","las.api.pvp.net").gsub("na","las") when "lan" url.gsub("na.api.pvp.net","lan.api.pvp.net").gsub("na","lan") when "oce" url.gsub("na.api.pvp.net","oce.api.pvp.net").gsub("na","oce") when "tr" url.gsub("na.api.pvp.net","tr.api.pvp.net").gsub("na","tr") when "ru" url.gsub("na.api.pvp.net","ru.api.pvp.net").gsub("na","ru") else url #Cause USA #1 end end |
#change_region(region) ⇒ Object
48 49 50 |
# File 'lib/league_api.rb', line 48 def change_region(region) @@default_region = region end |
#default_region ⇒ Object
44 45 46 |
# File 'lib/league_api.rb', line 44 def default_region @@default_region end |
#get_champion_names ⇒ Object
Returns an array of champion names
104 105 106 |
# File 'lib/league_api.rb', line 104 def get_champion_names Static.get_champion_list.keys end |
#get_item_names ⇒ Object
Returns an array of item names
109 110 111 112 113 114 115 |
# File 'lib/league_api.rb', line 109 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
128 129 130 131 |
# File 'lib/league_api.rb', line 128 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
123 124 125 |
# File 'lib/league_api.rb', line 123 def get_last_game_played(id, region=nil) Game.recent_games(id, region).first end |
#get_region(region) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/league_api.rb', line 56 def get_region(region) if region.nil? $region else region end end |
#get_summoner_id(str, region = nil) ⇒ Object
Return player id given the summoner name
118 119 120 |
# File 'lib/league_api.rb', line 118 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
134 135 136 |
# File 'lib/league_api.rb', line 134 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/league_api.rb', line 21 def make_request(base, modifier=nil, params=nil, region=nil) region = @@default_region if region.nil? base = LeagueApi.change_base(base, region) url = base + modifier if params params.each do |p| url << '?'+p[0]+'='+p[1] end url += '&api_key=' + @api_key else url += '?api_key=' + @api_key end uri = URI.parse(url) JSON.parse(uri.read) end |
#set_region(name) ⇒ Object
52 53 54 |
# File 'lib/league_api.rb', line 52 def set_region(name) $region = name end |