-
Notifications
You must be signed in to change notification settings - Fork 1
/
boxscoreusagev2.go
66 lines (56 loc) · 1.42 KB
/
boxscoreusagev2.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
package nag
import (
"encoding/json"
"fmt"
"net/http"
"github.com/dylantientcheu/nbacli/nag/params"
)
// BoxScoreUsageV2 wraps request to and response from boxscoreusagev2 endpoint.
type BoxScoreUsageV2 struct {
*Client
GameID string
StartRange string
EndRange string
RangeType string
StartPeriod string
EndPeriod string
Response *Response
}
// NewBoxScoreUsageV2 creates a default BoxScoreUsageV2 instance.
func NewBoxScoreUsageV2(id string) *BoxScoreUsageV2 {
return &BoxScoreUsageV2{
Client: NewDefaultClient(),
GameID: id,
StartRange: params.DefaultStartRange,
EndRange: params.DefaultEndRange,
RangeType: params.DefaultRangeType,
StartPeriod: params.Period.Default(),
EndPeriod: params.Period.Default(),
}
}
// Get sends a GET request to boxscoreusagev2 endpoint.
func (c *BoxScoreUsageV2) Get() error {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/boxscoreusagev2", c.BaseURL.String()), nil)
if err != nil {
return err
}
req.Header = DefaultStatsHeader
q := req.URL.Query()
q.Add("GameID", c.GameID)
q.Add("StartRange", c.StartRange)
q.Add("EndRange", c.EndRange)
q.Add("RangeType", c.RangeType)
q.Add("StartPeriod", c.StartPeriod)
q.Add("EndPeriod", c.EndPeriod)
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
}