/
Champion.go
59 lines (52 loc) · 1.33 KB
/
Champion.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
package gololapi
import (
"encoding/json"
"strconv"
"time"
)
//ChampionList Holds a list of Champion in Champions
type ChampionList struct {
Champions []Champion
}
//Champion Hold a champion data that was retrived by the Champion-V3 endpoint
type Champion struct {
ID int
FreeToPlay bool
Active bool
BotMMEnabled bool
BotEnabled bool
RankedPlayEnabled bool
}
//GetChampîons Make a request to the Champion-V3 endpoint and returns a ChampionList
func (api *GoLOLAPI) GetChampîons(onlyFreeToPlay bool) (champions ChampionList) {
var endpoint string
if onlyFreeToPlay {
endpoint = "/lol/platform/v3/champions?freeToPlay=true"
} else {
endpoint = "/lol/platform/v3/champions?freeToPlay=true"
}
response, e := api.RequestEndpoint(endpoint, time.Hour)
if e != nil {
panic(e)
}
champions = ChampionList{}
err := json.Unmarshal(response, &champions)
if err != nil {
panic(err)
}
return
}
//GetChampîon Make a request to the Champion-V3 endpoint and returns a Champion
func (api *GoLOLAPI) GetChampîon(ID int) (champion Champion) {
IDString := strconv.Itoa(ID)
response, e := api.RequestEndpoint("/lol/platform/v3/champions/"+IDString, time.Hour)
if e != nil {
panic(e)
}
champion = Champion{}
err := json.Unmarshal(response, &champion)
if err != nil {
panic(err)
}
return
}