api

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package api provides functions for interacting with the MLB gameday and xmlstats apis

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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 FormatURL

func FormatURL(t time.Time) string

FormatURL takes a time and returns the appropriate API URL to call

func GetLineScore

func GetLineScore(url string, target *LineScore) error

func GetSchedule

func GetSchedule(url string, target *Schedule) error

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 GameTeamLeagueRecord struct {
	Wins   int    `json:"wins"`
	Losses int    `json:"losses"`
	Pct    string `json:"pct"`
}

type GameTeamTeam

type GameTeamTeam struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Link string `json:"link"`
}

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

func FetchLineScore(id string) *LineScore

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 LineScoreTeam struct {
	Runs   int `json:"runs"`
	Hits   int `json:"hits"`
	Errors int `json:"errors"`
}

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 ScheduleGameStatus struct {
	AbstractGameState string `json:"abstractGameState"`
	CodedGameState    string `json:"codedGameState"`
	DetailedState     string `json:"detailedState"`
	StatusCode        string `json:"statusCode"`
	AbstractGameCode  string `json:"abstractGameCode"`
}

type ScheduleGameTeams

type ScheduleGameTeams struct {
	Away GameTeam `json:"away"`
	Home GameTeam `json:"home"`
}

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) Len

func (std Standings) Len() int

func (Standings) Less

func (std Standings) Less(i, j int) bool

func (Standings) PrintMasterStandingsTable

func (std Standings) PrintMasterStandingsTable()

PrintMasterStandingsTable prints a game-wide standings table to Stdout

func (Standings) PrintStandingsTable

func (std Standings) PrintStandingsTable(league, division string)

PrintStandingsTable prints a standings table for a particular league and division to Stdout

func (Standings) RestrictDivision

func (std Standings) RestrictDivision(division string) Standings

RestrictDivision restricts standings to a particular division

func (Standings) RestrictLeague

func (std Standings) RestrictLeague(league string) Standings

RestrictLeague restricts standings to a particular league

func (Standings) Swap

func (std Standings) Swap(i, j int)

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 StandingsTeamRecordTeam struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type StandingsTeamRecords

type StandingsTeamRecords []StandingsTeamRecord

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL