diff --git a/game.go b/game.go index f6c9e1b..3d01c63 100644 --- a/game.go +++ b/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 diff --git a/internal/statsapi/client.go b/internal/statsapi/client.go index 3845587..1c31181 100644 --- a/internal/statsapi/client.go +++ b/internal/statsapi/client.go @@ -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") diff --git a/internal/statsapi/feed.go b/internal/statsapi/feed.go index 1963272..b299468 100644 --- a/internal/statsapi/feed.go +++ b/internal/statsapi/feed.go @@ -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 diff --git a/internal/statsapi/schedule.go b/internal/statsapi/schedule.go index f628b75..ba9b90a 100644 --- a/internal/statsapi/schedule.go +++ b/internal/statsapi/schedule.go @@ -9,7 +9,7 @@ type ScheduleParams struct { TeamId string } -type ScheduleResponse struct { +type Schedule struct { TotalGames json.Number TotalGamesInProgress json.Number Dates []date diff --git a/main.go b/main.go index 42fb6d2..935c9e5 100644 --- a/main.go +++ b/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) }