-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_summoner.go
171 lines (140 loc) · 3.68 KB
/
api_summoner.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package riotapi
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
)
// https://developer.riotgames.com/api/methods#!/1079
// Summoner a summoner account data
type Summoner struct {
ID int `json:"id"`
Name string `json:"name"`
ProfileIcon int `json:"profileIconId"`
Level int `json:"summonerLevel"`
RevisionDate int `json:"revisionDate"`
}
// SummonerList a list of summoners with the key being the summoner ID in lower case
// It is a bit strange
type SummonerList map[string]*Summoner
// SummonerByName v1.4 of get summoner by name
func (c *APIClient) SummonerByName(name string) (s *Summoner, err error) {
var req *http.Request
req, err = c.genRequest("GET", "v1.4", c.genURL([]string{"summoner", "by-name", name}), nil)
if err != nil {
return nil, err
}
data, err := c.do(req, true)
if err != nil {
return nil, err
}
sl := make(SummonerList)
err = json.Unmarshal(data, &sl)
if err != nil {
return nil, err
} else if sl[strings.ToLower(name)] == nil {
return nil, fmt.Errorf("User does not exist")
}
return sl[strings.ToLower(name)], nil
}
// SummonerByIDs Get up to 40 summoners by ID
func (c *APIClient) SummonersByAccountID(ids []int) (sl SummonerList, err error) {
var req *http.Request
var sids []string
sl = make(SummonerList)
if len(ids) > 40 {
return sl, fmt.Errorf("Exceeds maximum of 40 ids")
}
for i := range ids {
sids = append(sids, strconv.Itoa(ids[i]))
}
req, err = c.genRequest("GET", "v1.4", c.genURL([]string{"summoner", "by-account", strings.Join(sids, ",")}), nil)
if err != nil {
return sl, err
}
data, err := c.do(req, true)
if err != nil {
return sl, err
}
err = json.Unmarshal(data, &sl)
if err != nil {
return nil, err
}
return sl, nil
}
// SummonersById get up to 40 summoners by their IDs
func (c *APIClient) SummonersByID(ids []int) (sl SummonerList, err error) {
var req *http.Request
var sids []string
sl = make(SummonerList)
if len(ids) > 40 {
return sl, fmt.Errorf("Exceeds maximum of 40 ids")
}
for i := range ids {
sids = append(sids, strconv.Itoa(ids[i]))
}
req, err = c.genRequest("GET", "v1.4", c.genURL([]string{"summoner", strings.Join(sids, ",")}), nil)
if err != nil {
return sl, err
}
data, err := c.do(req, true)
if err != nil {
return sl, err
}
err = json.Unmarshal(data, &sl)
if err != nil {
return nil, err
}
return sl, nil
}
// SummonerMasteries return up to 40 summoners masteries
func (c *APIClient) SummonerMasteries(ids []int) (sml SummonerMasteryList, err error) {
var req *http.Request
var sids []string
sml = make(SummonerMasteryList)
if len(ids) > 40 {
return sml, fmt.Errorf("Exceeds maximum of 40 ids")
}
for i := range ids {
sids = append(sids, strconv.Itoa(ids[i]))
}
req, err = c.genRequest("GET", "v1.4", c.genURL([]string{"summoner", strings.Join(sids, ","), "masteries"}), nil)
if err != nil {
return sml, err
}
data, err := c.do(req, true)
if err != nil {
return sml, err
}
err = json.Unmarshal(data, &sml)
if err != nil {
return nil, err
}
return sml, err
}
// SummonerRunes return a summoners masteries
func (c *APIClient) SummonerRunes(ids []int) (rp SummonerRuneList, err error) {
var req *http.Request
var sids []string
rp = make(SummonerRuneList)
if len(ids) > 40 {
return rp, fmt.Errorf("Exceeds maximum of 40 ids")
}
for i := range ids {
sids = append(sids, strconv.Itoa(ids[i]))
}
req, err = c.genRequest("GET", "v1.4", c.genURL([]string{"summoner", strings.Join(sids, ","), "runes"}), nil)
if err != nil {
return rp, err
}
data, err := c.do(req, true)
if err != nil {
return rp, err
}
err = json.Unmarshal(data, &rp)
if err != nil {
return nil, err
}
return rp, err
}