-
Notifications
You must be signed in to change notification settings - Fork 1
/
boxscoredefensive.go
49 lines (40 loc) · 949 Bytes
/
boxscoredefensive.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
package nag
import (
"encoding/json"
"fmt"
"net/http"
)
// BoxScoreDefensive wraps request to and response from boxscoredefensive endpoint.
type BoxScoreDefensive struct {
*Client
GameID string
Response *Response
}
// NewBoxScoreDefensive creates a default BoxScoreDefensive instance.
func NewBoxScoreDefensive(id string) *BoxScoreDefensive {
return &BoxScoreDefensive{
Client: NewDefaultClient(),
GameID: id,
}
}
// Get sends a GET request to boxscoredefensive endpoint.
func (c *BoxScoreDefensive) Get() error {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/boxscoredefensive", c.BaseURL.String()), nil)
if err != nil {
return err
}
req.Header = DefaultStatsHeader
q := req.URL.Query()
q.Add("GameID", c.GameID)
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
}