This repository has been archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectator.go
128 lines (111 loc) · 4.57 KB
/
spectator.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
package ionia
import (
"net/http"
"strconv"
)
// SpectatorService represents the Spectator-V3 API methods.
// https://developer.riotgames.com/api-methods/#spectator-v3
type SpectatorService service
// CurrentGameInfo contains current game info.
type CurrentGameInfo struct {
GameID int64 `json:"gameId"`
GameStartTime int64 `json:"gameStartTime"`
PlatformID string `json:"platformId"`
GameMode string `json:"gameMode"`
MapID int64 `json:"mapId"`
GameType string `json:"gameType"`
BannedChampions []BannedChampion `json:"bannedChampions"`
Observers Observer `json:"observers"`
Participants []CurrentGameParticipant `json:"participants"`
GameLength int64 `json:"gameLength"`
GameQueueConfigID int64 `json:"gameQueueConfigId"`
}
// BannedChampion contains information about a banned champion.
type BannedChampion struct {
PickTurn int `json:"pickTurn"`
ChampionID int64 `json:"championId"`
TeamID int64 `json:"teamId"`
}
// Observer contains observer information.
type Observer struct {
EncryptionKey string `json:"encryptionKey"`
}
// CurrentGameParticipant contains current game participant information.
type CurrentGameParticipant struct {
ProfileIconID int64 `json:"profileIconId"`
ChampionID int64 `json:"championId"`
SummonerName string `json:"summonerName"`
GameCustomizationObjects []GameCustomizationObject `json:"gameCustomizationObjects"`
Bot bool `json:"bot"`
Perks Perks `json:"perks"`
Spell2ID int64 `json:"spell2Id"`
TeamID int64 `json:"teamId"`
Spell1ID int64 `json:"spell1Id"`
SummonerID int64 `json:"summonerId"`
}
// GameCustomizationObject contains game customization information.
type GameCustomizationObject struct {
Category string `json:"category"`
Content string `json:"content"`
}
// Perks contains perks information.
type Perks struct {
PerkStyle int64 `json:"perkStyle"`
PerkIDs []int64 `json:"perkids"`
PerkSubStyle int64 `json:"perkSubStyle"`
}
// CurrentGame retrieves the current game information for the given summoner ID.
func (s *SpectatorService) CurrentGame(summonerID int64) (*CurrentGameInfo, *http.Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "lol/spectator/v3/active-games/by-summoner/"+strconv.FormatInt(summonerID, 10), nil)
if err != nil {
return nil, nil, err
}
c := &CurrentGameInfo{}
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, nil
}
// FeaturedGames contains featured games information.
type FeaturedGames struct {
ClientRefreshInterval int64 `json:"clientRefreshInterval"`
GameList []FeaturedGameInfo `json:"gameList"`
}
// FeaturedGameInfo contains featured game information.
type FeaturedGameInfo struct {
GameID int64 `json:"gameId"`
GameStartTime int64 `json:"gameStartTime"`
PlatformID string `json:"platformId"`
GameMode string `json:"gameMode"`
MapID int64 `json:"mapId"`
GameType string `json:"gameType"`
BannedChampions []BannedChampion `json:"bannedChampions"`
Observers Observer `json:"observers"`
Participants []Participant `json:"participants"`
GameLength int64 `json:"gameLength"`
GameQueueConfigID int64 `json:"gameQueueConfigId"`
}
// Participant contains participant information.
type Participant struct {
ProfileIconID int64 `json:"profileIconId"`
ChampionID int64 `json:"championId"`
SummonerName string `json:"summonerName"`
Bot bool `json:"bot"`
Spell2ID int64 `json:"spell2Id"`
TeamID int64 `json:"teamId"`
Spell1ID int64 `json:"spell1Id"`
}
// FeaturedGames retrieves a list of featured games.
func (s *SpectatorService) FeaturedGames() (*FeaturedGames, *http.Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "lol/spectator/v3/featured-games", nil)
if err != nil {
return nil, nil, err
}
f := &FeaturedGames{}
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, nil
}