Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the ChampionByKey function and fix a bug related to fetching the champion data from spectator participant. #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions datadragon/data_dragon.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ func (c *Client) GetChampionByID(id string) (ChampionDataExtended, error) {
return champion, nil
}

// GetChampion returns information about the champion with the given key
func (c *Client) GetChampionByKey(key string) (ChampionDataExtended, error) {
champions, err := c.GetChampions()
if err != nil {
return ChampionDataExtended{}, err
}
for _, champion := range champions {
if champion.Key == key {
return c.GetChampionByID(champion.ID)
}
}
return ChampionDataExtended{}, api.ErrNotFound
}

// GetChampion returns information about the champion with the given name
func (c *Client) GetChampion(name string) (ChampionDataExtended, error) {
champions, err := c.GetChampions()
Expand Down
2 changes: 1 addition & 1 deletion riot/lol/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ type CurrentGameParticipant struct {

// GetChampion returns the champion played by this participant
func (p *CurrentGameParticipant) GetChampion(client *datadragon.Client) (datadragon.ChampionDataExtended, error) {
return client.GetChampionByID(strconv.Itoa(p.ChampionID))
return client.GetChampionByKey(strconv.Itoa(p.ChampionID))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment on CurrentGameParticipant.ChampionID, describing that the value is actually the champion key. Also, I feel like this is a bug in the API :D

}

// GetSpell1 returns the first summoner spell of this participant
Expand Down
Loading