-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlive.go
68 lines (61 loc) · 2.4 KB
/
live.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
package opendota
import (
"net/http"
"github.com/dghubble/sling"
)
func newLiveService(sling *sling.Sling) *LiveService {
return &LiveService{
sling: sling.Path("live"),
}
}
// LiveService provides a method for accessing live games.
type LiveService struct {
sling *sling.Sling
}
// LiveGame represents a live game.
type LiveGame struct {
ActivateTime int64 `json:"activate_time"`
DeactivateTime int64 `json:"deactivate_time"`
ServerSteamID int64 `json:"server_steam_id"`
LobbyID int64 `json:"lobby_id"`
LeagueID int `json:"league_id"`
LobbyType int `json:"lobby_type"`
GameTime int `json:"game_time"`
Delay int `json:"delay"`
Spectators int `json:"spectators"`
GameMode int `json:"game_mode"`
AverageMmr int `json:"average_mmr"`
SortScore int `json:"sort_score"`
LastUpdateTime int `json:"last_update_time"`
RadiantLead int `json:"radiant_lead"`
RadiantScore int `json:"radiant_score"`
DireScore int `json:"dire_score"`
Players []LivePlayers `json:"players"`
BuildingState int `json:"building_state"`
MatchID int64 `json:"match_id"`
RadiantTeamName string `json:"team_name_radiant"`
RadiantTeamID int `json:"team_id_radiant"`
DireTeamName string `json:"team_name_dire"`
DireTeamID int `json:"team_id_dire"`
}
type LivePlayers struct {
AccountID int `json:"account_id"`
HeroID int `json:"hero_id"`
Name string `json:"name,omitempty"`
CountryCode string `json:"country_code,omitempty"`
FantasyRole int `json:"fantasy_role,omitempty"`
TeamID int `json:"team_id,omitempty"`
TeamName string `json:"team_name,omitempty"`
TeamTag string `json:"team_tag,omitempty"`
IsLocked bool `json:"is_locked,omitempty"`
IsPro bool `json:"is_pro,omitempty"`
LockedUntil int `json:"locked_until,omitempty"`
}
// Live returns a collection of the top live games.
// https://docs.opendota.com/#tag/live%2Fpaths%2F~1live%2Fget
func (s *LiveService) Live() ([]LiveGame, *http.Response, error) {
livegames := new([]LiveGame)
apiError := new(APIError)
resp, err := s.sling.New().Receive(livegames, apiError)
return *livegames, resp, relevantError(err, *apiError)
}