forked from KnutZuidema/golio
/
champion_mastery.go
60 lines (52 loc) · 1.69 KB
/
champion_mastery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package lol
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/Benbentwo/golio/internal"
)
// ChampionMasteryClient provides methods for the champion mastery endpoints of the
// League of Legends API.
type ChampionMasteryClient struct {
c *internal.Client
}
// List returns information about masteries for the summoner with the given ID
func (c *ChampionMasteryClient) List(summonerID string) ([]*ChampionMastery, error) {
logger := c.logger().WithField("method", "List")
var masteries []*ChampionMastery
if err := c.c.GetInto(
fmt.Sprintf(endpointGetChampionMasteries, summonerID),
&masteries,
); err != nil {
logger.Debug(err)
return nil, err
}
return masteries, nil
}
// Get returns information about the mastery of the champion with the given ID the summoner with the
// given ID has
func (c *ChampionMasteryClient) Get(summonerID, championID string) (*ChampionMastery, error) {
logger := c.logger().WithField("method", "Get")
var mastery *ChampionMastery
if err := c.c.GetInto(
fmt.Sprintf(endpointGetChampionMastery, summonerID, championID),
&mastery,
); err != nil {
logger.Debug(err)
return nil, err
}
return mastery, nil
}
// GetTotal returns the accumulated mastery score of all champions played by the summoner with the
// given ID
func (c *ChampionMasteryClient) GetTotal(summonerID string) (int, error) {
logger := c.logger().WithField("method", "GetTotal")
var score int
if err := c.c.GetInto(fmt.Sprintf(endpointGetChampionMasteryTotalScore, summonerID), &score); err != nil {
logger.Debug(err)
return 0, err
}
return score, nil
}
func (c *ChampionMasteryClient) logger() log.FieldLogger {
return c.c.Logger().WithField("category", "champion mastery")
}