-
Notifications
You must be signed in to change notification settings - Fork 1
/
commonallplayers.go
58 lines (48 loc) · 1.24 KB
/
commonallplayers.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
package nag
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/dylantientcheu/nbacli/nag/params"
)
// CommonAllPlayers wraps request to and response from commonallplayers endpoint.
type CommonAllPlayers struct {
*Client
IsOnlyCurrentSeason int
LeagueID string
Season string
Response *Response
}
// NewCommonAllPlayers creates a default CommonAllPlayers instance.
func NewCommonAllPlayers() *CommonAllPlayers {
return &CommonAllPlayers{
Client: NewDefaultClient(),
IsOnlyCurrentSeason: 0,
LeagueID: params.LeagueID.Default(),
Season: params.CurrentSeason,
}
}
// Get sends a GET request to commonallplayers endpoint.
func (c *CommonAllPlayers) Get() error {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/commonallplayers", c.BaseURL.String()), nil)
if err != nil {
return err
}
req.Header = DefaultStatsHeader
q := req.URL.Query()
q.Add("IsOnlyCurrentSeason", strconv.Itoa(c.IsOnlyCurrentSeason))
q.Add("LeagueID", c.LeagueID)
q.Add("Season", c.Season)
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
}