Documentation
¶
Overview ¶
Package nba is the library behind the nba command line: the HTTP client, request shaping, and the typed data models for stats.nba.com.
The NBA Stats API requires specific HTTP headers on every request or it returns 403. This client sets all required headers automatically.
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetRoster(ctx context.Context, teamID int, season string) ([]*RosterPlayer, error)
- func (c *Client) GetScoreboard(ctx context.Context, date string) ([]*Game, error)
- func (c *Client) GetStandings(ctx context.Context, season string) ([]*Standing, error)
- func (c *Client) GetTeamStats(ctx context.Context, season string, limit int) ([]*TeamStats, error)
- type Domain
- type Game
- type RosterPlayer
- type Standing
- type TeamStats
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const Host = "stats.nba.com"
Host is the NBA Stats API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to stats.nba.com over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 500ms minimum gap between requests, and three retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client settings.
func (*Client) GetScoreboard ¶
GetScoreboard fetches the game scoreboard for a given date (YYYY-MM-DD).
func (*Client) GetStandings ¶
GetStandings fetches league standings for the given season.
type Domain ¶
type Domain struct{}
Domain is the nba driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Game ¶
type Game struct {
GameID string `kit:"id" json:"game_id"`
Date string `json:"date"`
HomeTeamID int `json:"home_team_id"`
AwayTeamID int `json:"away_team_id"`
StatusText string `json:"status"`
Season string `json:"season"`
}
Game is one game from the scoreboard.
type RosterPlayer ¶
type RosterPlayer struct {
TeamID int `kit:"id" json:"team_id"`
Name string `json:"name"`
Number string `json:"number"`
Position string `json:"position"`
Height string `json:"height"`
Weight string `json:"weight"`
}
RosterPlayer is one player entry on a team roster.
type Standing ¶
type Standing struct {
TeamID int `kit:"id" json:"team_id"`
City string `json:"city"`
Name string `json:"name"`
Conference string `json:"conference"`
Division string `json:"division"`
Wins int `json:"wins"`
Losses int `json:"losses"`
WinPct float64 `json:"win_pct"`
}
Standing is one team's season standing.
type TeamStats ¶
type TeamStats struct {
TeamID int `kit:"id" json:"team_id"`
Name string `json:"name"`
GP int `json:"games_played"`
Wins int `json:"wins"`
Losses int `json:"losses"`
PTS float64 `json:"pts_per_game"`
REB float64 `json:"reb_per_game"`
AST float64 `json:"ast_per_game"`
}
TeamStats holds per-game averages for one team in a season.