mlb

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ARI ...
	ARI = "ARI"
	// ATL ...
	ATL = "ATL"
	// BAL ...
	BAL = "BAL"
	// BOS ...
	BOS = "BOS"
	// CHC ...
	CHC = "CHC"
	// CIN ...
	CIN = "CIN"
	// CLE ...
	CLE = "CLE"
	// COL ...
	COL = "COL"
	// CWS ...
	CWS = "CWS"
	// DET ...
	DET = "DET"
	// HOU ...
	HOU = "HOU"
	// KC ...
	KC = "KC"
	// LAA ...
	LAA = "LAA"
	// LAD ...
	LAD = "LAD"
	// MIA ...
	MIA = "MIA"
	// MIL ...
	MIL = "MIL"
	// MIN ...
	MIN = "MIN"
	// NYM ...
	NYM = "NYM"
	// NYY ...
	NYY = "NYY"
	// OAK ...
	OAK = "OAK"
	// PHI ...
	PHI = "PHI"
	// PIT ...
	PIT = "PIT"
	// SD ...
	SD = "SD"
	// SEA ...
	SEA = "SEA"
	// SF ...
	SF = "SF"
	// STL ...
	STL = "STL"
	// TB ...
	TB = "TB"
	// TEX ...
	TEX = "TEX"
	// TOR ...
	TOR = "TOR"
	// WSH ...
	WSH = "WSH"
)
View Source
const (

	// DateFormat is the game schedule format for querying a particular day from the API
	DateFormat = "2006-01-02"
)

Variables

View Source
var ALL = []string{ARI, ATL, BAL, BOS, CHC, CIN, CLE, COL, CWS, DET, HOU, KC, LAA, LAD, MIA, MIL, MIN, NYM, NYY, OAK, PHI, PIT, SD, SEA, SF, STL, TB, TEX, TOR, WSH}

ALL contains all of the teams in the league

Functions

func GetLiveGame

func GetLiveGame(ctx context.Context, link string) (sportboard.Game, error)

GetLiveGame ...

func GetLogo(ctx context.Context, logoKey string, logoConf *logo.Config, bounds image.Rectangle, defaultConfigs *[]*logo.Config) (*logo.Logo, error)

GetLogo is a generic function that can be used outside the scope of an MLB type. Useful for testing

func MockLiveGameGetter added in v0.0.2

func MockLiveGameGetter(ctx context.Context, link string) (sportboard.Game, error)

MockLiveGameGetter implements an mlb.LiveGameGetter

Types

type DefaultLogoConfigs added in v0.0.3

type DefaultLogoConfigs *[]*logo.Config

DefaultLogoConfigs contains default logo alignedment configurations

type Game

type Game struct {
	GameGetter LiveGameGetter
	ID         int    `json:"gamePk"`
	Link       string `json:"link"`
	Teams      *struct {
		Home *gameTeam `json:"home"`
		Away *gameTeam `json:"away"`
	} `json:"teams"`
	GameTime time.Time
	GameDate string `json:"gameDate"`
	GameData *struct {
		DateTime *struct {
			DateTime string `json:"dateTime,omitempty"`
		} `json:"datetime,omitempty"`
		Status *struct {
			AbstractGameState string `json:"abstractGameState,omitempty"`
			DetailedState     string `json:"detailedState,omitempty"`
			StatusCode        string `json:"statusCode,omitempty"`
		} `json:"status,omitempty"`
		Teams *struct {
			Home *Team `json:"home"`
			Away *Team `json:"away"`
		} `json:"teams"`
	} `json:"gameData,omitempty"`
	LiveData *struct {
		Linescore *struct {
			CurrentInning        int    `json:"currentInning"`
			CurrentInningOrdinal string `json:"currentInningOrdinal"`
			InningState          string `json:"inningState"`
			Teams                *struct {
				Home *gameTeam `json:"home"`
				Away *gameTeam `json:"away"`
			} `json:"teams"`
		} `json:"linescore"`
	} `json:"liveData"`
}

Game ...

func (*Game) AwayTeam

func (g *Game) AwayTeam() (sportboard.Team, error)

AwayTeam ...

func (*Game) GetClock

func (g *Game) GetClock() (string, error)

GetClock represent bottom or top of inning

func (*Game) GetID

func (g *Game) GetID() int

GetID ...

func (g *Game) GetLink() (string, error)

GetLink ...

func (*Game) GetQuarter

func (g *Game) GetQuarter() (string, error)

GetQuarter returns the inning

func (*Game) GetStartTime

func (g *Game) GetStartTime(ctx context.Context) (time.Time, error)

GetStartTime ...

func (*Game) GetUpdate

func (g *Game) GetUpdate(ctx context.Context) (sportboard.Game, error)

GetUpdate ...

func (*Game) HomeTeam

func (g *Game) HomeTeam() (sportboard.Team, error)

HomeTeam ...

func (*Game) IsComplete

func (g *Game) IsComplete() (bool, error)

IsComplete ...

func (*Game) IsLive

func (g *Game) IsLive() (bool, error)

IsLive ...

func (*Game) IsPostponed added in v0.0.7

func (g *Game) IsPostponed() (bool, error)

IsPostponed ...

type LiveGameGetter

type LiveGameGetter func(ctx context.Context, link string) (sportboard.Game, error)

LiveGameGetter is a func used to retrieve an updated sportboard.Game

type MLB

type MLB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MLB implements a sportboard.API

func New

func New(ctx context.Context, logger *zap.Logger) (*MLB, error)

New ...

func (*MLB) AllTeamAbbreviations

func (m *MLB) AllTeamAbbreviations() []string

AllTeamAbbreviations returns a list of all teams in the league

func (*MLB) CacheClear added in v0.0.15

func (m *MLB) CacheClear(ctx context.Context)

CacheClear ...

func (*MLB) DateStr

func (m *MLB) DateStr(d time.Time) string

DateStr ...

func (m *MLB) GetLogo(ctx context.Context, logoKey string, logoConf *logo.Config, bounds image.Rectangle) (*logo.Logo, error)

GetLogo ...

func (*MLB) GetScheduledGames

func (m *MLB) GetScheduledGames(ctx context.Context, date time.Time) ([]sportboard.Game, error)

GetScheduledGames ...

func (*MLB) GetTeams

func (m *MLB) GetTeams(ctx context.Context) ([]sportboard.Team, error)

GetTeams ...

func (*MLB) GetWatchTeams added in v0.0.12

func (m *MLB) GetWatchTeams(teams []string) []string

GetWatchTeams parses 'ALL' or divisions and adds teams accordingly

func (*MLB) HTTPPathPrefix

func (m *MLB) HTTPPathPrefix() string

HTTPPathPrefix returns the path prefix for the HTTP handlers for this board

func (*MLB) League

func (m *MLB) League() string

League ...

func (*MLB) TeamFromAbbreviation

func (m *MLB) TeamFromAbbreviation(ctx context.Context, abbreviation string) (sportboard.Team, error)

TeamFromAbbreviation ...

func (*MLB) TeamRank added in v0.0.13

func (m *MLB) TeamRank(ctx context.Context, team sportboard.Team) string

TeamRank ...

func (*MLB) TeamRecord added in v0.0.13

func (m *MLB) TeamRecord(ctx context.Context, team sportboard.Team) string

TeamRecord ...

func (*MLB) UpdateGames

func (m *MLB) UpdateGames(ctx context.Context, dateStr string) error

UpdateGames updates scheduled games

func (*MLB) UpdateTeams

func (m *MLB) UpdateTeams(ctx context.Context) error

UpdateTeams ...

type MockMLBAPI added in v0.0.2

type MockMLBAPI struct {
	// contains filtered or unexported fields
}

MockMLBAPI implements a sportboard.API. Used to test the MLB board

func NewMock added in v0.0.2

func NewMock(logger *zap.Logger) (*MockMLBAPI, error)

NewMock ...

func (*MockMLBAPI) AllTeamAbbreviations added in v0.0.2

func (m *MockMLBAPI) AllTeamAbbreviations() []string

AllTeamAbbreviations ...

func (*MockMLBAPI) CacheClear added in v0.0.15

func (m *MockMLBAPI) CacheClear(ctx context.Context)

CacheClear ...

func (*MockMLBAPI) DateStr added in v0.0.2

func (m *MockMLBAPI) DateStr(d time.Time) string

DateStr ...

func (m *MockMLBAPI) GetLogo(ctx context.Context, logoKey string, logoConf *logo.Config, bounds image.Rectangle) (*logo.Logo, error)

GetLogo ...

func (*MockMLBAPI) GetScheduledGames added in v0.0.2

func (m *MockMLBAPI) GetScheduledGames(ctx context.Context, date time.Time) ([]sportboard.Game, error)

GetScheduledGames ...

func (*MockMLBAPI) GetTeams added in v0.0.2

func (m *MockMLBAPI) GetTeams(ctx context.Context) ([]sportboard.Team, error)

GetTeams ...

func (*MockMLBAPI) GetWatchTeams added in v0.0.12

func (m *MockMLBAPI) GetWatchTeams(teams []string) []string

GetWatchTeams ...

func (*MockMLBAPI) HTTPPathPrefix added in v0.0.2

func (m *MockMLBAPI) HTTPPathPrefix() string

HTTPPathPrefix ...

func (*MockMLBAPI) League added in v0.0.2

func (m *MockMLBAPI) League() string

League ...

func (*MockMLBAPI) TeamFromAbbreviation added in v0.0.2

func (m *MockMLBAPI) TeamFromAbbreviation(ctx context.Context, abbrev string) (sportboard.Team, error)

TeamFromAbbreviation ...

func (*MockMLBAPI) TeamRank added in v0.0.13

func (m *MockMLBAPI) TeamRank(ctx context.Context, team sportboard.Team) string

TeamRank ...

func (*MockMLBAPI) TeamRecord added in v0.0.13

func (m *MockMLBAPI) TeamRecord(ctx context.Context, team sportboard.Team) string

TeamRecord ...

func (*MockMLBAPI) UpdateGames added in v0.0.2

func (m *MockMLBAPI) UpdateGames(ctx context.Context, dateStr string) error

UpdateGames ...

func (*MockMLBAPI) UpdateTeams added in v0.0.2

func (m *MockMLBAPI) UpdateTeams(ctx context.Context) error

UpdateTeams ...

type Team

type Team struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	Abbreviation string `json:"abbreviation"`
	Link         string `json:"link,omitempty"`
	DivisionData struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Link string `json:"link"`
	} `json:"division"`
	Division *division
	Runs     int
}

Team implements a sportboard.Team

func GetTeams

func GetTeams(ctx context.Context) ([]*Team, error)

GetTeams ...

func (*Team) GetAbbreviation

func (t *Team) GetAbbreviation() string

GetAbbreviation ...

func (*Team) GetID

func (t *Team) GetID() int

GetID ...

func (*Team) GetName

func (t *Team) GetName() string

GetName ...

func (*Team) Score

func (t *Team) Score() int

Score ...

Jump to

Keyboard shortcuts

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