-
Notifications
You must be signed in to change notification settings - Fork 1
/
scoreboardv2.go
61 lines (49 loc) · 1.14 KB
/
scoreboardv2.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"
"time"
"github.com/dylantientcheu/nbacli/nag/params"
)
// ScoreBoardV2 wraps request to and response from scoreboardv2 endpoint.
type ScoreBoardV2 struct {
*Client
DayOffset int
GameDate string
LeagueID string
Response *Response
}
// NewScoreBoardV2 creates a default ScoreBoardV2 instance.
func NewScoreBoardV2(date time.Time) *ScoreBoardV2 {
return &ScoreBoardV2{
Client: NewDefaultClient(),
DayOffset: 0,
GameDate: date.Format("2006-01-02"),
LeagueID: params.LeagueID.Default(),
}
}
// Get sends a GET request to scoreboardv2 endpoint.
func (c *ScoreBoardV2) Get() error {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/scoreboardv2", c.BaseURL.String()), nil)
if err != nil {
return err
}
req.Header = DefaultStatsHeader
q := req.URL.Query()
q.Add("DayOffset", strconv.Itoa(c.DayOffset))
q.Add("GameDate", c.GameDate)
q.Add("LeagueID", c.LeagueID)
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
}