mlblive/internal/statsapi/feed.go

71 lines
1.4 KiB
Go
Raw Normal View History

2024-07-02 04:16:44 +00:00
package statsapi
import (
"encoding/json"
)
type FeedParams struct {
GamePk string
}
type FeedResponse struct {
MetaData metadata
LiveData livedata
}
type metadata struct {
TimeStamp string
}
type livedata struct {
Plays plays
}
type plays struct {
AllPlays []Play
CurrentPlay Play
ScoringPlays []json.Number
}
type Play struct {
Result result
About about
AtBatIndex int
}
type result struct {
Event string
Description string
RBI int
AwayScore int
HomeScore int
}
type about struct {
AtBatIndex json.Number
IsTopInning bool
Inning json.Number
IsScoringPlay bool
CaptivatingIndex json.Number
}
func (p *Play) Patch(patch Patch) {
instructions := patch.Diff
stem := "/liveData/plays/currentPlay"
for _, i := range instructions {
if i.Op == "add" && i.Path == stem+"/result/description" {
p.Result.Description = i.Value.(string)
} else if i.Op == "replace" && i.Path == stem+"/about/isScoringPlay" {
p.About.IsScoringPlay = i.Value.(bool)
} else if i.Op == "replace" && i.Path == stem+"/result/homeScore" {
p.Result.HomeScore = int(i.Value.(float64))
} else if i.Op == "replace" && i.Path == stem+"/result/awayScore" {
p.Result.AwayScore = int(i.Value.(float64))
} else if i.Op == "add" && i.Path == stem+"/result/event" {
p.Result.Event = i.Value.(string)
} else if i.Op == "replace" && i.Path == stem+"/atBatIndex" {
p.AtBatIndex = int(i.Value.(float64))
}
}
}