-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatches.go
171 lines (147 loc) · 5.34 KB
/
matches.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 etf2l
import (
"context"
"fmt"
"github.com/pkg/errors"
)
type MatchClan struct {
Country string `json:"country"`
Drop bool `json:"drop"`
ID int `json:"id"`
Name string `json:"name"`
Steam struct {
Avatar string `json:"avatar"`
Group string `json:"group"`
} `json:"steam"`
URL string `json:"url"`
}
type MatchCompetition struct {
Category string `json:"category"`
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
}
type Match struct {
Clan1 MatchClan `json:"clan1"`
Clan2 MatchClan `json:"clan2"`
Competition MatchCompetition `json:"competition"`
Submitted int `json:"submitted"`
Defaultwin bool `json:"defaultwin"`
Division Division `json:"division"`
ID int `json:"id"`
Maps []string `json:"maps"`
R1 int `json:"r1"`
R2 int `json:"r2"`
Round string `json:"round"`
Time int `json:"time"`
Week int `json:"week"`
Urls struct {
Self string `json:"self"`
API string `json:"api"`
} `json:"urls"`
}
type pagedMatches struct {
CurrentPage int `json:"current_page"`
Data []Match `json:"data"`
FirstPageURL string `json:"first_page_url"`
From int `json:"from"`
LastPage int `json:"last_page"`
LastPageURL string `json:"last_page_url"`
Links []links `json:"links"`
NextPageURL *string `json:"next_page_url"`
Path string `json:"path"`
PerPage int `json:"per_page"`
PrevPageURL *string `json:"prev_page_url"`
To int `json:"to"`
Total int `json:"total"`
}
type matchesResponse struct {
Pager pagedMatches `json:"results"`
Status Status `json:"status"`
}
func (resp matchesResponse) NextURL(r Recursive) (string, error) {
if !r.IsRecursive() || resp.Pager.NextPageURL == nil {
return "", ErrEOF
}
nextPath, err := getPath(*resp.Pager.NextPageURL)
if err != nil {
return "", err
}
return nextPath, nil
}
type MatchesOpts struct {
BaseOpts
Clan1 int `url:"clan1,omitempty"` // Team TeamID of the blu team.
Clan2 int `url:"clan2,omitempty"` // Team TeamID of the red team.
Vs int `url:"vs,omitempty"` // Team TeamID of either team.
Scheduled int `url:"scheduled,omitempty"` // If set to 1, returns matches that have yet to be played. If set to 0, returns matches that are over.
Competition int `url:"competition,omitempty"` // Limit your search to a specific competition. Expects a competition TeamID.
From int `url:"from,omitempty"` // UNIX timestamp that limits results to everything after the timestamp.
To int `url:"to,omitempty"` // UNIX timestamp that limits results to everything before the time.
Division string `url:"division,omitempty"` // Name of the division in which the competition was played.
TeamType string `url:"team_type,omitempty"` // Name of the type of team.
Round string `url:"round,omitempty"` // Name of the current round.
Players []string `url:"players,omitempty"` // A list of ETF2L user TeamID's. Returns only matches in which any of the provided players participated.
}
func (client *Client) Matches(ctx context.Context, httpClient HTTPExecutor, opts Recursive) ([]Match, error) {
var matches []Match
curPath := "/matches"
for {
var resp matchesResponse
if err := client.call(ctx, httpClient, curPath, nil, &resp); err != nil {
return nil, err
}
matches = append(matches, resp.Pager.Data...)
nextURL, err := resp.NextURL(opts)
if err != nil {
if errors.Is(err, ErrEOF) {
break
}
return nil, err
}
curPath = nextURL
}
return matches, nil
}
type MatchMapResult struct {
MatchOrder int `json:"match_order"`
Clan1 int `json:"clan1"`
Clan2 int `json:"clan2"`
Map string `json:"map"`
GoldenCap bool `json:"golden_cap"`
}
type MatchDetails struct {
Clan1 MatchClan `json:"clan1"`
Clan2 MatchClan `json:"clan2"`
Competition MatchCompetition `json:"competition"`
Defaultwin bool `json:"defaultwin"`
Division interface{} `json:"division"`
ID int `json:"id"`
Maps []string `json:"maps"`
R1 int `json:"r1"`
R2 int `json:"r2"`
Round string `json:"round"`
Time int `json:"time"`
Submitted int `json:"submitted"`
Week int `json:"week"`
Urls struct {
Self string `json:"self"`
API string `json:"api"`
} `json:"urls"`
Players []interface{} `json:"players"`
ByeWeek bool `json:"bye_week"`
Demos []interface{} `json:"demos"`
MapResults []MatchMapResult `json:"map_results"`
}
type matchDetailsResponse struct {
Match MatchDetails `json:"match"`
Status Status `json:"status"`
}
func (client *Client) MatchDetails(ctx context.Context, httpClient HTTPExecutor, leagueMatchID int) (*MatchDetails, error) {
var resp matchDetailsResponse
if err := client.call(ctx, httpClient, fmt.Sprintf("/matches/%d", leagueMatchID), nil, &resp); err != nil {
return nil, err
}
return &resp.Match, nil
}