simplify feed struct and move out of statsapi package
This commit is contained in:
parent
866ba4055d
commit
610dd6898d
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright © 2024 filifa
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation, either version 3 of the License, or (at your option) any later
|
|
||||||
version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
|
||||||
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package statsapi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Feed struct {
|
|
||||||
MetaData metadata
|
|
||||||
LiveData livedata
|
|
||||||
}
|
|
||||||
|
|
||||||
type metadata struct {
|
|
||||||
TimeStamp string
|
|
||||||
}
|
|
||||||
|
|
||||||
type livedata struct {
|
|
||||||
Plays plays
|
|
||||||
Linescore linescore
|
|
||||||
}
|
|
||||||
|
|
||||||
type linescore struct {
|
|
||||||
Teams teams
|
|
||||||
}
|
|
||||||
|
|
||||||
type teams struct {
|
|
||||||
Home team
|
|
||||||
Away team
|
|
||||||
}
|
|
||||||
|
|
||||||
type team struct {
|
|
||||||
Runs json.Number
|
|
||||||
}
|
|
||||||
|
|
||||||
type plays struct {
|
|
||||||
AllPlays []Play
|
|
||||||
CurrentPlay Play
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -30,6 +30,14 @@ import (
|
||||||
|
|
||||||
var gamePk int
|
var gamePk int
|
||||||
|
|
||||||
|
type Feed struct {
|
||||||
|
MetaData metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
type metadata struct {
|
||||||
|
TimeStamp string
|
||||||
|
}
|
||||||
|
|
||||||
func patch(feedResp []byte, gamePk, ts, updateId string) ([]byte, error) {
|
func patch(feedResp []byte, gamePk, ts, updateId string) ([]byte, error) {
|
||||||
diffPatchResp, err := statsapi.RequestDiffPatch(gamePk, ts, updateId)
|
diffPatchResp, err := statsapi.RequestDiffPatch(gamePk, ts, updateId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,7 +82,7 @@ func handleUnexpectedClose(gamePk string) (*statsapi.GamedayWebsocket, []byte, e
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFeed(ws *statsapi.GamedayWebsocket, feedResp []byte, gamePk string) ([]byte, error) {
|
func updateFeed(ws *statsapi.GamedayWebsocket, feedResp []byte, gamePk string) ([]byte, error) {
|
||||||
var feed statsapi.Feed
|
var feed Feed
|
||||||
err := json.Unmarshal(feedResp, &feed)
|
err := json.Unmarshal(feedResp, &feed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue