Class: RiotAPI::Summoner

Inherits:
Object
  • Object
show all
Defined in:
lib/riot_api/summoner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, region) ⇒ Summoner

Returns a new instance of Summoner.



4
5
6
7
8
9
10
11
# File 'lib/riot_api/summoner.rb', line 4

def initialize(data, region)
	@region = region
	data.each do |key, value|
		key = key.underscore
		self.class.send(:attr_accessor, key.to_sym)
		instance_variable_set("@#{key}", value)
	end
end

Instance Attribute Details

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/riot_api/summoner.rb', line 3

def region
  @region
end

Class Method Details

.find(region, summoner_id) ⇒ Object

Find a summoner by it’s summoner ID



24
25
26
27
28
29
30
31
# File 'lib/riot_api/summoner.rb', line 24

def self.find(region, summoner_id) 
	response = RiotAPI::Client.get(region, "summoner/#{summoner_id}")
	if response
		Summoner.new(response)
	else
		nil
	end
end

.find_by_name(region, name) ⇒ Object

Find a summoner by it’s name



14
15
16
17
18
19
20
21
# File 'lib/riot_api/summoner.rb', line 14

def self.find_by_name(region, name) 
	response = RiotAPI::Client.get(region, "summoner/by-name/#{name}")
	if response
		Summoner.new(response, region)
	else
		nil
	end
end

.names_by_ids(region, summoner_ids) ⇒ Object

Returns an array of names. summoner_ids should be an array of summoner_ids



34
35
36
37
38
# File 'lib/riot_api/summoner.rb', line 34

def self.names_by_ids(region, summoner_ids)
	summoner_ids = summoner_ids.join(',').first(40).compact
	response = RiotAPI::Client.get(region, "summoner/#{summoner_ids}/name")
	response || []
end

Instance Method Details

#mastery_pagesObject

Returns the MasteryPage array for the Summoner instance



41
42
43
# File 'lib/riot_api/summoner.rb', line 41

def mastery_pages
	MasteryPage.find(self.region, self.id)
end

#player_stats(season = 'SEASON3') ⇒ Object

Returns the Player Stats for the Summoner



51
52
53
# File 'lib/riot_api/summoner.rb', line 51

def player_stats(season='SEASON3')
	PlayerStatSummary.find(self.region, self.id, season)
end

#recent_gamesObject

Returns the last 10 games for the Summoner



56
57
58
# File 'lib/riot_api/summoner.rb', line 56

def recent_games
	Game.recent_games(self.region, self.id)
end

#rune_pagesObject

Returns the RunePage array for the Summoner instance



46
47
48
# File 'lib/riot_api/summoner.rb', line 46

def rune_pages
	RunePage.find(self.region, self.id)
end