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