-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmatchhistory.go
78 lines (65 loc) · 1.86 KB
/
matchhistory.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
package goriot
import (
"fmt"
"strconv"
)
type PlayerHistory struct {
Matches []MatchSummary `json:"matches"`
}
type MatchSummary struct {
MapID int `json:"mapId"`
MatchCreation int64 `json:"matchCreation"`
MatchDuration int64 `json:"matchDuration"`
MatchVersion string `json:"matchVersion"`
ParticipantIdentities []ParticipantIdentity `json:"participantIdentities"`
Participants []Participant `json:"participants"`
QueueType string `json:"queueType"`
Region string `json:"region"`
Season string `json:"season"`
}
func MatchHistoryBySummonerID(
region string,
summonerID int64,
championIDs []int64,
rankedQueues []string,
beginIndex int,
endIndex int) (
playerHistory PlayerHistory, err error) {
if !IsKeySet() {
return playerHistory, ErrAPIKeyNotSet
}
// create a filter for specific champions
championIDStr := intURLParameter(championIDs).String()
// check to see if specific queues are being filtered
rankedQueuesStr := strURLParameter(rankedQueues).String()
// check for indexing
beginIndexStr := ""
if beginIndex > -1 {
beginIndexStr = strconv.Itoa(beginIndex)
}
endIndexStr := ""
if endIndex > -1 {
endIndexStr = strconv.Itoa(endIndex)
}
// build argument string
args := fmt.Sprintf(
"api_key=%v&championIds=%v&rankedQueues=%v&beginIndex=%v&endIndex=%v",
apikey,
championIDStr,
rankedQueuesStr,
beginIndexStr,
endIndexStr)
// build url string, request, return payload
url := fmt.Sprintf(
"https://%v.%v/lol/%v/v2.2/matchhistory/%d?%v",
region,
BaseAPIURL,
region,
summonerID,
args)
err = requestAndUnmarshal(url, &playerHistory)
if err != nil {
return playerHistory, err
}
return playerHistory, nil
}