Class: RiotAPI::Summoner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_idObject

Encrypted account ID. Max length 56 characters.



7
8
9
# File 'lib/riot_api/resources/summoner.rb', line 7

def 
  @account_id
end

#idObject

Encrypted summoner ID. Max length 63 characters.



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

def id
  @id
end

#nameObject

Summoner name.



16
17
18
# File 'lib/riot_api/resources/summoner.rb', line 16

def name
  @name
end

#profile_icon_idObject

ID of the summoner icon associated with the summoner.



10
11
12
# File 'lib/riot_api/resources/summoner.rb', line 10

def profile_icon_id
  @profile_icon_id
end

#puuidObject

Encrypted PUUID. Exact length of 78 characters.



13
14
15
# File 'lib/riot_api/resources/summoner.rb', line 13

def puuid
  @puuid
end

#regionObject

The summoner associated region, e.g.: +:br+, +:na+



25
26
27
# File 'lib/riot_api/resources/summoner.rb', line 25

def region
  @region
end

#revision_dateObject

Date summoner was last modified specified as epoch milliseconds. The following events will update this timestamp: profile icon change, playing the tutorial or advanced tutorial, finishing a game, summoner name change



22
23
24
# File 'lib/riot_api/resources/summoner.rb', line 22

def revision_date
  @revision_date
end

#summoner_levelObject

Summoner level associated with the summoner.



19
20
21
# File 'lib/riot_api/resources/summoner.rb', line 19

def summoner_level
  @summoner_level
end

Class Method Details

.find(options = {}) ⇒ RiotAPI::Summoner

Finds a summoner using the Riot Games API.

Examples:

Find a summoner by name

RiotAPI::Summoner.find(region: :br, name: "Your Name")

Parameters:

  • options (Hash) (defaults to: {})

    The options and filters to find the summoner

Options Hash (options):

  • :region (String)

    The League of Legends region associated with the account (e.g. +:br+, +:na+, etc)

  • :name (String)

    The summoner name

  • :id (String)

    The encrypted summoner ID

  • :account_id (String)

    The encrypted account ID

  • :puuid (String)

    The encrypted PUUID

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/riot_api/resources/summoner.rb', line 37

def self.find(options = {})
  mandatory_options = [:region]
  accepted_filters = [:name, :id, :account_id, :puuid]

  unless (mandatory_options - options.keys).empty?
    raise ArgumentError, "A required parameter was not informed. The required paramaters are #{mandatory_options}"
  end

  request_path = (
    if options.key?(:name)
      "/lol/summoner/v4/summoners/by-name/#{options[:name]}"
    elsif options.key?(:id)
      "/lol/summoner/v4/summoners/#{options[:id]}"
    elsif options.key?(:account_id)
      "/lol/summoner/v4/summoners/by-account/#{options[:account_id]}"
    elsif options.key?(:puuid)
      "/lol/summoner/v4/summoners/by-puuid/#{options[:puuid]}"
    else
      raise ArgumentError, "The informed filter is not accepted. The accepted filters are #{accepted_filters}"
    end
  )

  response = RiotAPI.client.request(:get, request_path, options[:region])
  instance = self.from_json(response)
  instance.region = options[:region]
  instance
end

.from_json(json) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/riot_api/resources/summoner.rb', line 65

def self.from_json(json)
  self.new.tap do |s|
    s.id = json["id"]
    s. = json["account_id"]
    s.profile_icon_id = json["profile_icon_id"]
    s.puuid = json["puuid"]
    s.name = json["name"]
    s.summoner_level = json["summoner_level"]
    s.revision_date = json["revision_date"]
  end
end

Instance Method Details

#masteriesArray<RiotAPI::ChampionMastery>

Returns a list of champion mastery for each champion

Returns:



79
80
81
# File 'lib/riot_api/resources/summoner.rb', line 79

def masteries
  ChampionMastery.where(region: self.region, summoner_id: self.id)
end