/
gen_play_by_play.go
63 lines (52 loc) · 1.63 KB
/
gen_play_by_play.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
package baller
import (
"net/url"
)
type PlayByPlayOptions struct {
GameID string
StartPeriod int
EndPeriod int
}
type PlayByPlayResponse struct {
PlayByPlay []PlayByPlayPlayByPlay
AvailableVideo []PlayByPlayAvailableVideo
}
func (c *Client) PlayByPlay(options *PlayByPlayOptions) (*PlayByPlayResponse, error) {
var (
q = url.Values{}
url = baseURL + "playbyplay?"
dest PlayByPlayResponse
res result
)
q.Set("GameID", encodeString(options.GameID))
q.Set("StartPeriod", encodeInt(options.StartPeriod))
q.Set("EndPeriod", encodeInt(options.EndPeriod))
if err := c.do(url+q.Encode(), &res); err != nil {
return nil, err
}
err := res.unmarshalResultSets(map[string]interface{}{
"PlayByPlay": &dest.PlayByPlay,
"AvailableVideo": &dest.AvailableVideo,
})
if err != nil {
return nil, err
}
return &dest, nil
}
type PlayByPlayPlayByPlay struct {
GameID string `header:"GAME_ID"`
Eventnum int `header:"EVENTNUM"`
Eventmsgtype int `header:"EVENTMSGTYPE"`
Eventmsgactiontype int `header:"EVENTMSGACTIONTYPE"`
Period int `header:"PERIOD"`
Wctimestring string `header:"WCTIMESTRING"`
Pctimestring string `header:"PCTIMESTRING"`
Homedescription string `header:"HOMEDESCRIPTION"`
Neutraldescription interface{} `header:"NEUTRALDESCRIPTION"`
Visitordescription string `header:"VISITORDESCRIPTION"`
Score string `header:"SCORE"`
Scoremargin string `header:"SCOREMARGIN"`
}
type PlayByPlayAvailableVideo struct {
VideoAvailableFlag int `header:"VIDEO_AVAILABLE_FLAG"`
}