Documentation
¶
Overview ¶
Package api provides functions for interacting with the MLB gameday and xmlstats apis
Index ¶
- Variables
- func PrintBoxScoreTable(sg ScheduleGame, ls *LineScore)
- type Client
- type IDLink
- type IDNameLink
- type LineScore
- type LineScoreDefense
- type LineScoreInning
- type LineScoreOffense
- type LineScorePlayer
- type LineScoreTeam
- type LineScoreTeams
- type RosterResponse
- type Schedule
- type ScheduleDate
- type ScheduleGame
- type ScheduleGameStatus
- type ScheduleTeam
- type ScheduleTeams
- type Standings
- type StandingsDetailedRecords
- type StandingsDivisionRecord
- type StandingsGenericRecord
- type StandingsLeagueRecord
- type StandingsRecord
- type StandingsStreak
- type StandingsTeamRecord
Constants ¶
This section is empty.
Variables ¶
var Locs = []string{
"Arizona",
"Atlanta",
"Baltimore",
"Boston",
"Chicago",
"Chicago",
"Cincinnati",
"Cleveland",
"Colorado",
"Detroit",
"Miami",
"Houston",
"Kansas City",
"Los Angeles",
"Los Angeles",
"Milwaukee",
"Minnesota",
"New York",
"New York",
"Oakland",
"Philadelphia",
"Pittsburgh",
"St. Louis",
"San Diego",
"San Francisco",
"Seattle",
"Tampa Bay",
"Texas",
"Toronto",
"Washington",
}
Locs is a list of team locations
var Teams = []string{
"Diamondbacks",
"Braves",
"Red Sox",
"Cubs",
"White Sox",
"Reds",
"Indians",
"Rockies",
"Tigers",
"Marlins",
"Astros",
"Royals",
"Angels",
"Dodgers",
"Brewers",
"Twins",
"Mets",
"Yankees",
"Athletics",
"Phillies",
"Pirates",
"Cardinals",
"Padres",
"Giants",
"Mariners",
"Rays",
"Rangers",
"Blue Jays",
"Nationals",
}
Teams is a list of team names
var TeamsWithLocs = []string{
"Arizona Diamondbacks",
"Atlanta Braves",
"Boston Red Sox",
"Chicago Cubs",
"Chicago White Sox",
"Cincinnati Reds",
"Cleveland Indians",
"Colorado Rockies",
"Detroit Tigers",
"Miami Marlins",
"Houston Astros",
"Kansas City Royals",
"Los Angeles Angels",
"Los Angeles Dodgers",
"Milwaukee Brewers",
"Minnesota Twins",
"New York Mets",
"New York Yankees",
"Oakland Athletics",
"Philadelphia Phillies",
"Pittsburgh Pirates",
"St. Louis Cardinals",
"San Diego Padres",
"San Francisco Giants",
"Seattle Mariners",
"Tampa Bay Rays",
"Texas Rangers",
"Toronto Blue Jays",
"Washington Nationals",
}
TeamsWithLocs is a slice of full MLB team names with their location included
Functions ¶
func PrintBoxScoreTable ¶
func PrintBoxScoreTable(sg ScheduleGame, ls *LineScore)
PrintBoxScoreTable prints a box score to Stdout
Types ¶
type Client ¶ added in v0.4.0
Client is a wrapper aroudn an HTTP client for the MLB API
func NewClient ¶ added in v0.4.0
func NewClient() *Client
NewClient is a constructor for HTTP clients
type IDNameLink ¶ added in v0.4.0
IDNameLink is a generic struct that can represent several different types
type LineScore ¶
type LineScore struct {
CurrentInning int `json:"currentInning"`
CurrentInningOrdinal string `json:"currentInningOrdinal"`
InningState string `json:"inningState"`
InningHalf string `json:"inningHalf"`
IsTopInning bool `json:"isTopInning"`
ScheduledInnings int `json:"scheduledInnings"`
Innings []LineScoreInning `json:"innings"`
Teams LineScoreTeams `json:"teams"`
Defense LineScoreDefense `json:"defense"`
Offense LineScoreOffense `json:"offense"`
Balls int `json:"balls"`
Strikes int `json:"strikes"`
Outs int `json:"outs"`
}
LineScore represents an MLB API linescore
func FetchLineScore ¶
FetchLineScore gets a line score from the MLB API
type LineScoreDefense ¶ added in v0.4.0
type LineScoreDefense struct {
Pitcher LineScorePlayer `json:"pitcher"`
Catcher LineScorePlayer `json:"catcher"`
First LineScorePlayer `json:"first"`
Second LineScorePlayer `json:"second"`
Third LineScorePlayer `json:"third"`
Shortstop LineScorePlayer `json:"shortstop"`
Left LineScorePlayer `json:"left"`
Center LineScorePlayer `json:"center"`
Right LineScorePlayer `json:"right"`
Team IDNameLink `json:"team"`
}
LineScoreDefense gives information about players on defense
type LineScoreInning ¶
type LineScoreInning struct {
Num int `json:"num"`
OrdinalNum string `json:"ordinalNum"`
Home LineScoreTeam `json:"home,omitempty"`
Away LineScoreTeam `json:"away,omitempty"`
}
LineScoreInning represents an inning in a Linescore
type LineScoreOffense ¶ added in v0.4.0
type LineScoreOffense struct {
Batter LineScorePlayer `json:"batter"`
OnDeck LineScorePlayer `json:"onDeck"`
InHole LineScorePlayer `json:"inHole"`
Second LineScorePlayer `json:"second"`
Pitcher LineScorePlayer `json:"pitcher"`
Team IDNameLink `json:"team"`
}
LineScoreOffense gives information about players on offense
type LineScorePlayer ¶ added in v0.4.0
type LineScorePlayer struct {
ID int `json:"id"`
FullName string `json:"fullName"`
Link string `json:"link"`
}
LineScorePlayer has a full name
type LineScoreTeam ¶
type LineScoreTeam struct {
Runs int `json:"runs"`
Hits int `json:"hits"`
Errors int `json:"errors"`
LeftOnBase int `json:"leftOnBase"`
}
LineScoreTeam is a team's representation in a LineScore
type LineScoreTeams ¶
type LineScoreTeams struct {
Home LineScoreTeam `json:"home"`
Away LineScoreTeam `json:"away"`
}
LineScoreTeams maps a LineScoreTeam to Home and another to Away
type RosterResponse ¶ added in v0.4.0
type RosterResponse struct {
Roster []struct {
Person struct {
ID int `json:"id"`
FullName string `json:"fullName"`
Link string `json:"link"`
} `json:"person"`
JerseyNumber string `json:"jerseyNumber"`
Position struct {
Code string `json:"code"`
Name string `json:"name"`
Type string `json:"type"`
Abbreviation string `json:"abbreviation"`
} `json:"position"`
Status struct {
Code string `json:"code"`
Description string `json:"description"`
} `json:"status"`
ParentTeamID int `json:"parentTeamId"`
} `json:"roster"`
Link string `json:"link"`
TeamID int `json:"teamId"`
RosterType string `json:"rosterType"`
}
RosterResponse is a response from /v1/teams/<teamid>/roster
type Schedule ¶
type Schedule struct {
TotalItems int `json:"totalItems"`
TotalEvents int `json:"totalEvents"`
TotalGames int `json:"totalGames"`
TotalGamesInProgress int `json:"totalGamesInProgress"`
Dates []ScheduleDate `json:"dates"`
}
Schedule is a day's worth of games from the MLB API
type ScheduleDate ¶
type ScheduleDate struct {
Date string `json:"date"`
TotalItems int `json:"totalItems"`
TotalEvents int `json:"totalEvents"`
TotalGames int `json:"totalGames"`
TotalGamesInProgress int `json:"totalGamesInProgress"`
Games []ScheduleGame `json:"games"`
Events []interface{} `json:"events"`
}
ScheduleDate is one day's worth of games
type ScheduleGame ¶
type ScheduleGame struct {
GamePk int `json:"gamePk"`
Link string `json:"link"`
GameType string `json:"gameType"`
Season string `json:"season"`
GameDate time.Time `json:"gameDate"`
Status ScheduleGameStatus `json:"status,omitempty"`
Teams ScheduleTeams `json:"teams"`
Venue IDNameLink `json:"venue"`
Content struct {
Link string `json:"link"`
} `json:"content"`
IsTie bool `json:"isTie,omitempty"`
GameNumber int `json:"gameNumber"`
PublicFacing bool `json:"publicFacing"`
DoubleHeader string `json:"doubleHeader"`
GamedayType string `json:"gamedayType"`
Tiebreaker string `json:"tiebreaker"`
CalendarEventID string `json:"calendarEventID"`
SeasonDisplay string `json:"seasonDisplay"`
DayNight string `json:"dayNight"`
ScheduledInnings int `json:"scheduledInnings"`
GamesInSeries int `json:"gamesInSeries"`
SeriesGameNumber int `json:"seriesGameNumber"`
SeriesDescription string `json:"seriesDescription"`
RecordSource string `json:"recordSource"`
IfNecessary string `json:"ifNecessary"`
IfNecessaryDescription string `json:"ifNecessaryDescription"`
RescheduleDate time.Time `json:"rescheduleDate,omitempty"`
}
ScheduleGame is a game that is part of a schedule
func FetchGames ¶
func FetchGames(t time.Time) []ScheduleGame
FetchGames gets the latest game data from the MLB API and returns a list of games on the day specified by `t`
func (ScheduleGame) FindTeam ¶
func (g ScheduleGame) FindTeam(team string) bool
FindTeam determines if the team `team` is playing in `game`
func (ScheduleGame) HasTeam ¶
func (g ScheduleGame) HasTeam(abbrv string) bool
HasTeam determines if the team `abbrv` is playing in `game`
func (ScheduleGame) IsOver ¶
func (g ScheduleGame) IsOver() bool
IsOver determines whether or not a game is over
func (ScheduleGame) ParseTime ¶ added in v0.3.2
func (g ScheduleGame) ParseTime() time.Time
ParseTime returns a game's time localized to the current time zone
type ScheduleGameStatus ¶
type ScheduleGameStatus struct {
AbstractGameState string `json:"abstractGameState"`
CodedGameState string `json:"codedGameState"`
DetailedState string `json:"detailedState"`
StatusCode string `json:"statusCode"`
Reason string `json:"reason,omitempty"`
AbstractGameCode string `json:"abstractGameCode"`
}
ScheduleGameStatus is a status of a game that is part of a Schedule
type ScheduleTeam ¶ added in v0.4.0
type ScheduleTeam struct {
LeagueRecord StandingsGenericRecord `json:"leagueRecord"`
Score int `json:"score"`
Team IDNameLink `json:"team"`
IsWinner bool `json:"isWinner"`
SplitSquad bool `json:"splitSquad"`
SeriesNumber int `json:"seriesNumber"`
}
ScheduleTeam is a team that's part of a Schedule
type ScheduleTeams ¶ added in v0.4.0
type ScheduleTeams struct {
Away ScheduleTeam `json:"away"`
Home ScheduleTeam `json:"home"`
}
ScheduleTeams is a struct that maps a ScheduleTeam to both Away and Home
type Standings ¶
type Standings struct {
Records []StandingsRecord `json:"records"`
}
Standings is a wrapper for StandingsRecords
func FetchStandings ¶
func FetchStandings() *Standings
FetchStandings gets the latest game data from the MLB API and returns a list of games on the day specified by `t`
func (*Standings) FlattenToTeamRecordsSlice ¶ added in v0.4.0
func (std *Standings) FlattenToTeamRecordsSlice() []StandingsTeamRecord
FlattenToTeamRecordsSlice takes a Standings pointer and returns a flattened slice of TeamRecords
func (*Standings) PrintMasterStandingsTable ¶
func (std *Standings) PrintMasterStandingsTable()
PrintMasterStandingsTable prints a game-wide standings table to Stdout
func (*Standings) PrintStandingsTable ¶
PrintStandingsTable prints a standings table for a particular league and division to Stdout
type StandingsDetailedRecords ¶ added in v0.4.0
type StandingsDetailedRecords struct {
SplitRecords []StandingsGenericRecord `json:"splitRecords"`
DivisionRecords []StandingsDivisionRecord `json:"divisionRecords"`
OverallRecords []StandingsGenericRecord `json:"overallRecords"`
LeagueRecords []StandingsLeagueRecord `json:"leagueRecords"`
ExpectedRecords []StandingsGenericRecord `json:"expectedRecords"`
}
StandingsDetailedRecords give more granular information about a team's record
type StandingsDivisionRecord ¶ added in v0.4.0
type StandingsDivisionRecord struct {
Wins int `json:"wins"`
Losses int `json:"losses"`
Pct string `json:"pct"`
Division IDNameLink `json:"division"`
}
StandingsDivisionRecord is a team's record against a division
type StandingsGenericRecord ¶ added in v0.4.0
type StandingsGenericRecord struct {
Wins int `json:"wins"`
Losses int `json:"losses"`
Type string `json:"type"`
Pct string `json:"pct"`
}
StandingsGenericRecord is a generic representation of several more specialized types of records that come from the standings API
type StandingsLeagueRecord ¶ added in v0.4.0
type StandingsLeagueRecord struct {
Wins int `json:"wins"`
Losses int `json:"losses"`
Pct string `json:"pct"`
League IDNameLink `json:"league"`
}
StandingsLeagueRecord is a team's record against a league
type StandingsRecord ¶ added in v0.4.0
type StandingsRecord struct {
StandingsType string `json:"standingsType"`
League IDLink `json:"league"`
Division IDNameLink `json:"division"`
Sport IDLink `json:"sport"`
LastUpdated time.Time `json:"lastUpdated"`
TeamRecords []StandingsTeamRecord `json:"teamRecords"`
}
StandingsRecord is an important standings API struct
func RestrictDivision ¶ added in v0.4.0
func RestrictDivision(records []StandingsRecord, division string) []StandingsRecord
RestrictDivision restricts standings to a particular division
func RestrictLeague ¶ added in v0.4.0
func RestrictLeague(records []StandingsRecord, league string) []StandingsRecord
RestrictLeague restricts standings to a particular league
type StandingsStreak ¶ added in v0.4.0
type StandingsStreak struct {
StreakType string `json:"streakType"`
StreakNumber int `json:"streakNumber"`
StreakCode string `json:"streakCode"`
}
StandingsStreak is a winning or losing streak. You usually want StreakCode, which looks like `W7`.
type StandingsTeamRecord ¶
type StandingsTeamRecord struct {
Team IDNameLink `json:"team"`
Season string `json:"season"`
Streak StandingsStreak `json:"streak"`
ClinchIndicator string `json:"clinchIndicator,omitempty"`
DivisionRank string `json:"divisionRank"`
LeagueRank string `json:"leagueRank"`
SportRank string `json:"sportRank"`
GamesPlayed int `json:"gamesPlayed"`
GamesBack string `json:"gamesBack"`
WildCardGamesBack string `json:"wildCardGamesBack"`
LeagueGamesBack string `json:"leagueGamesBack"`
SpringLeagueGamesBack string `json:"springLeagueGamesBack"`
SportGamesBack string `json:"sportGamesBack"`
DivisionGamesBack string `json:"divisionGamesBack"`
ConferenceGamesBack string `json:"conferenceGamesBack"`
LeagueRecord StandingsLeagueRecord `json:"leagueRecord"`
LastUpdated time.Time `json:"lastUpdated"`
Records StandingsDetailedRecords `json:"records"`
RunsAllowed int `json:"runsAllowed"`
RunsScored int `json:"runsScored"`
DivisionChamp bool `json:"divisionChamp"`
DivisionLeader bool `json:"divisionLeader"`
HasWildcard bool `json:"hasWildcard"`
Clinched bool `json:"clinched"`
EliminationNumber string `json:"eliminationNumber"`
WildCardEliminationNumber string `json:"wildCardEliminationNumber"`
MagicNumber string `json:"magicNumber,omitempty"`
Wins int `json:"wins"`
Losses int `json:"losses"`
RunDifferential int `json:"runDifferential"`
WinningPercentage string `json:"winningPercentage"`
WildCardRank string `json:"wildCardRank,omitempty"`
}
StandingsTeamRecord gives more detail about a team in the standings