-
Notifications
You must be signed in to change notification settings - Fork 1
/
alltimeleadersgrids.go
61 lines (51 loc) · 1.31 KB
/
alltimeleadersgrids.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
package nag
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/dylantientcheu/nbacli/nag/params"
)
// AllTimeLeadersGrids wraps request to and response from alltimeleadersgrids endpoint.
type AllTimeLeadersGrids struct {
*Client
LeagueID string
PerMode params.PerMode
SeasonType params.SeasonType
TopX int
Response *Response
}
// NewAllTimeLeadersGrids creates a default AllTimeLeadersGrids instance.
func NewAllTimeLeadersGrids() *AllTimeLeadersGrids {
return &AllTimeLeadersGrids{
Client: NewDefaultClient(),
LeagueID: params.LeagueID.Default(),
PerMode: params.DefaultPerMode,
SeasonType: params.DefaultSeasonType,
TopX: 10,
}
}
// Get sends a GET request to alltimeleadersgrids endpoint.
func (c *AllTimeLeadersGrids) Get() error {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/alltimeleadersgrids", c.BaseURL.String()), nil)
if err != nil {
return err
}
req.Header = DefaultStatsHeader
q := req.URL.Query()
q.Add("LeagueID", c.LeagueID)
q.Add("PerMode", string(c.PerMode))
q.Add("SeasonType", string(c.SeasonType))
q.Add("TopX", strconv.Itoa(c.TopX))
req.URL.RawQuery = q.Encode()
b, err := c.Do(req)
if err != nil {
return err
}
var res Response
if err := json.Unmarshal(b, &res); err != nil {
return err
}
c.Response = &res
return nil
}