Documentation ¶
Overview ¶
Package api provides functions for interacting with the MLB gameday and xmlstats apis
Index ¶
- Variables
- func FormatURL(t time.Time) string
- func GetLineScore(url string, target *LineScore) error
- func GetSchedule(url string, target *Schedule) error
- func GetStandingsJSON(url string, target *StandingsResponse) error
- func PrintBoxScoreTable(sg ScheduleGame, ls *LineScore)
- type GameTeam
- type GameTeamLeagueRecord
- type GameTeamTeam
- type LineScore
- type LineScoreInning
- type LineScoreInningTeam
- type LineScoreTeam
- type LineScoreTeams
- type Schedule
- type ScheduleDate
- type ScheduleGame
- type ScheduleGameStatus
- type ScheduleGameTeams
- type Standing
- type Standings
- func (std Standings) Len() int
- func (std Standings) Less(i, j int) bool
- func (std Standings) PrintMasterStandingsTable()
- func (std Standings) PrintStandingsTable(league, division string)
- func (std Standings) RestrictDivision(division string) Standings
- func (std Standings) RestrictLeague(league string) Standings
- func (std Standings) Swap(i, j int)
- type StandingsRecords
- type StandingsResponse
- type StandingsTeamRecord
- type StandingsTeamRecordStreak
- type StandingsTeamRecordTeam
- type StandingsTeamRecords
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",
}
Functions ¶
func GetLineScore ¶
func GetSchedule ¶
GetSchedule unmarshals an MLB JSON API response into an MLBRoot
func GetStandingsJSON ¶
func GetStandingsJSON(url string, target *StandingsResponse) error
GetStandingsJSON unmarshals an XML API response into a list of games
func PrintBoxScoreTable ¶
func PrintBoxScoreTable(sg ScheduleGame, ls *LineScore)
PrintBoxScoreTable prints a box score to Stdout
Types ¶
type GameTeam ¶
type GameTeam struct { LeagueRecord GameTeamLeagueRecord Score int `json:"score"` Team GameTeamTeam `json:"team"` IsWinner bool `json:"isWinner"` SplitSquad bool `json:"splitSquad"` SeriesNumber int `json:"seriesNumber"` }
type GameTeamLeagueRecord ¶
type GameTeamTeam ¶
type LineScore ¶
type LineScore struct { CurrentInning int `json:"currentInning"` CurrentInningOrdinal string `json:"currentInningOrdinal"` InningHalf string `json:"inningHalf"` IsTopInning bool `json:"isTopInning"` ScheduledInnings int `json:"scheduledInnings"` Innings []LineScoreInning `json:"innings"` Teams LineScoreTeams `json:"teams"` }
func FetchLineScore ¶
type LineScoreInning ¶
type LineScoreInning struct { Num int `json:"num"` OrdinalNum string `json:"ordinalNum"` Away LineScoreInningTeam `json:"away"` Home LineScoreInningTeam `json:"home"` }
type LineScoreInningTeam ¶
type LineScoreInningTeam struct {
Runs int `json:"runs"`
}
type LineScoreTeam ¶
type LineScoreTeams ¶
type LineScoreTeams struct { Away LineScoreTeam `json:"away"` Home LineScoreTeam `json:"home"` }
type Schedule ¶
type Schedule struct {
Dates []ScheduleDate `json:"dates"`
}
Schedule is the root of an MLB JSON API response
type ScheduleDate ¶
type ScheduleDate struct { Date string `json:"date"` Games []ScheduleGame `json:"games"` }
ScheduleDate represents a data root from the MLB JSON API
type ScheduleGame ¶
type ScheduleGame struct { ID int `json:"gamePk"` Time string `json:"gameDate"` Status ScheduleGameStatus `json:"status"` Teams ScheduleGameTeams `json:"teams"` }
Game is an individual game
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
type ScheduleGameStatus ¶
type ScheduleGameTeams ¶
type Standing ¶
type Standing struct { ID string `json:"team_id"` Rank int `json:"rank"` OrdinalRank string `json:"ordinal_rank"` Won int `json:"won"` Lost int `json:"lost"` FirstName string `json:"first_name"` LastName string `json:"last_name"` League string `json:"conference"` Division string `json:"division"` GamesBack float64 `json:"games_back"` GamesPlayed int `json:"games_played"` WinPercentage string `json:"win_percentage"` Streak string `json:"streak"` }
Standing is an individual standing
type Standings ¶
type Standings []Standing
Standings is a slice of multiple Standings
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) 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
func (Standings) RestrictDivision ¶
RestrictDivision restricts standings to a particular division
func (Standings) RestrictLeague ¶
RestrictLeague restricts standings to a particular league
type StandingsRecords ¶
type StandingsRecords struct {
TeamRecords []StandingsTeamRecords `json:"teamRecords"`
}
type StandingsResponse ¶
type StandingsResponse struct { Date string `json:"standings_date"` StandingList Standings `json:"standing"` }
StandingsResponse is a json root response from the API
type StandingsTeamRecord ¶
type StandingsTeamRecord struct { Team StandingsTeamRecordTeam `json:"team"` Streak StandingsTeamRecordStreak `json:"streak"` GamesBack string `json:"gamesBack"` }
type StandingsTeamRecordStreak ¶
type StandingsTeamRecordStreak struct {
StreakCode string `json:"streakCode"`
}
type StandingsTeamRecordTeam ¶
type StandingsTeamRecords ¶
type StandingsTeamRecords []StandingsTeamRecord