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