nba

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

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

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client settings.

func (*Client) GetRoster

func (c *Client) GetRoster(ctx context.Context, teamID int, season string) ([]*RosterPlayer, error)

GetRoster fetches the roster for a team in a given season.

func (*Client) GetScoreboard

func (c *Client) GetScoreboard(ctx context.Context, date string) ([]*Game, error)

GetScoreboard fetches the game scoreboard for a given date (YYYY-MM-DD).

func (*Client) GetStandings

func (c *Client) GetStandings(ctx context.Context, season string) ([]*Standing, error)

GetStandings fetches league standings for the given season.

func (*Client) GetTeamStats

func (c *Client) GetTeamStats(ctx context.Context, season string, limit int) ([]*TeamStats, error)

GetTeamStats fetches per-game team stats for the given season.

type Domain

type Domain struct{}

Domain is the nba driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

Jump to

Keyboard shortcuts

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