change names
This commit is contained in:
parent
0a09ed2091
commit
516ad5f467
2
game.go
2
game.go
|
@ -8,7 +8,7 @@ type Game struct {
|
|||
AwayScore uint
|
||||
}
|
||||
|
||||
func (g *Game) Update(feed *statsapi.FeedResponse) {
|
||||
func (g *Game) Update(feed *statsapi.Feed) {
|
||||
homeScore, _ := (*feed)["liveData"].(map[string]any)["linescore"].(map[string]any)["teams"].(map[string]any)["home"].(map[string]any)["runs"].(float64)
|
||||
awayScore, _ := (*feed)["liveData"].(map[string]any)["linescore"].(map[string]any)["teams"].(map[string]any)["away"].(map[string]any)["runs"].(float64)
|
||||
// FIXME: currentPlay/result doesn't always have description
|
||||
|
|
|
@ -8,16 +8,16 @@ import (
|
|||
|
||||
var DefaultClient = NewClient(http.DefaultClient)
|
||||
|
||||
func Schedule(sportId, teamId string) ([]byte, error) {
|
||||
return DefaultClient.Schedule(sportId, teamId)
|
||||
func RequestSchedule(sportId, teamId string) ([]byte, error) {
|
||||
return DefaultClient.RequestSchedule(sportId, teamId)
|
||||
}
|
||||
|
||||
func Feed(gamePk string) ([]byte, error) {
|
||||
return DefaultClient.Feed(gamePk)
|
||||
func RequestFeed(gamePk string) ([]byte, error) {
|
||||
return DefaultClient.RequestFeed(gamePk)
|
||||
}
|
||||
|
||||
func DiffPatch(gamePk, startTimecode, pushUpdateId string) ([]byte, error) {
|
||||
return DefaultClient.DiffPatch(gamePk, startTimecode, pushUpdateId)
|
||||
func RequestDiffPatch(gamePk, startTimecode, pushUpdateId string) ([]byte, error) {
|
||||
return DefaultClient.RequestDiffPatch(gamePk, startTimecode, pushUpdateId)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
|
@ -35,7 +35,7 @@ func NewClient(c *http.Client) *Client {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Client) Schedule(sportId, teamId string) ([]byte, error) {
|
||||
func (c *Client) RequestSchedule(sportId, teamId string) ([]byte, error) {
|
||||
endpoint := url.URL{Path: "api/v1/schedule"}
|
||||
query := endpoint.Query()
|
||||
query.Add("sportId", sportId)
|
||||
|
@ -47,14 +47,14 @@ func (c *Client) Schedule(sportId, teamId string) ([]byte, error) {
|
|||
return c.get(url.String())
|
||||
}
|
||||
|
||||
func (c *Client) Feed(gamePk string) ([]byte, error) {
|
||||
func (c *Client) RequestFeed(gamePk string) ([]byte, error) {
|
||||
endpoint := url.URL{Path: "api/v1.1/game/" + gamePk + "/feed/live"}
|
||||
url := c.baseURL.ResolveReference(&endpoint)
|
||||
|
||||
return c.get(url.String())
|
||||
}
|
||||
|
||||
func (c *Client) DiffPatch(gamePk, startTimecode, pushUpdateId string) ([]byte, error) {
|
||||
func (c *Client) RequestDiffPatch(gamePk, startTimecode, pushUpdateId string) ([]byte, error) {
|
||||
endpoint := url.URL{Path: "api/v1.1/game/" + gamePk + "/feed/live/diffPatch"}
|
||||
query := endpoint.Query()
|
||||
query.Add("language", "en")
|
||||
|
|
|
@ -2,17 +2,13 @@ package statsapi
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FeedParams struct {
|
||||
GamePk string
|
||||
}
|
||||
|
||||
type FeedResponse map[string]any
|
||||
type Feed map[string]any
|
||||
|
||||
type Play struct {
|
||||
Result result
|
||||
|
|
|
@ -9,7 +9,7 @@ type ScheduleParams struct {
|
|||
TeamId string
|
||||
}
|
||||
|
||||
type ScheduleResponse struct {
|
||||
type Schedule struct {
|
||||
TotalGames json.Number
|
||||
TotalGamesInProgress json.Number
|
||||
Dates []date
|
||||
|
|
12
main.go
12
main.go
|
@ -34,12 +34,12 @@ func getGamePk() string {
|
|||
log.Fatal("invalid team ID")
|
||||
}
|
||||
|
||||
sched, err := statsapi.Schedule("1", strconv.Itoa(id))
|
||||
sched, err := statsapi.RequestSchedule("1", strconv.Itoa(id))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var s statsapi.ScheduleResponse
|
||||
var s statsapi.Schedule
|
||||
err = json.Unmarshal(sched, &s)
|
||||
|
||||
gamePk := s.Dates[0].Games[0].GamePk.String()
|
||||
|
@ -76,12 +76,12 @@ func main() {
|
|||
ch := make(chan error)
|
||||
go ws.KeepAlive(10*time.Second, ch)
|
||||
|
||||
feed, err := statsapi.Feed(gamePk)
|
||||
feed, err := statsapi.RequestFeed(gamePk)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var f statsapi.FeedResponse
|
||||
var f statsapi.Feed
|
||||
err = json.Unmarshal(feed, &f)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -99,9 +99,9 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
diffPatch, err := statsapi.DiffPatch(gamePk, ts, p.UpdateId)
|
||||
diffPatch, err := statsapi.RequestDiffPatch(gamePk, ts, p.UpdateId)
|
||||
if err != nil {
|
||||
feed, err = statsapi.Feed(gamePk)
|
||||
feed, err = statsapi.RequestFeed(gamePk)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue