-
Notifications
You must be signed in to change notification settings - Fork 8
/
publicmatch.go
49 lines (42 loc) · 1.55 KB
/
publicmatch.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
package opendota
import (
"net/http"
"github.com/dghubble/sling"
)
func newPublicMatchService(sling *sling.Sling) *PublicMatchService {
return &PublicMatchService{
sling: sling.Path("publicMatches"),
}
}
// PublicMatchService provides a method for accessing public matches.
type PublicMatchService struct {
sling *sling.Sling
}
// PublicMatchParam can be used to customize a public match query.
type PublicMatchParam struct {
MmrAscending int `url:"mmr_ascending,omitempty"`
MmrDescending int `url:"mmr_descending,omitempty"`
LessThanMatchID int64 `url:"less_than_match_id,omitempty"`
}
// PublicMatch represents a public match in Dota 2.
type PublicMatch struct {
MatchID int64 `json:"match_id"`
MatchSeqNum int64 `json:"match_seq_num"`
RadiantWin bool `json:"radiant_win"`
StartTime int `json:"start_time"`
Duration int `json:"duration"`
AvgMmr int `json:"avg_mmr"`
NumMmr int `json:"num_mmr"`
LobbyType int `json:"lobby_type"`
GameMode int `json:"game_mode"`
RadiantTeam string `json:"radiant_team"`
DireTeam string `json:"dire_team"`
}
// Matches takes optional params and returns public match data.
// https://docs.opendota.com/#tag/public-matches%2Fpaths%2F~1publicMatches%2Fget
func (s *PublicMatchService) Matches(params *PublicMatchParam) ([]PublicMatch, *http.Response, error) {
publicmatches := new([]PublicMatch)
apiError := new(APIError)
resp, err := s.sling.New().QueryStruct(params).Receive(publicmatches, apiError)
return *publicmatches, resp, relevantError(err, *apiError)
}