Documentation
¶
Overview ¶
Package espn is the library behind the espn command line: the HTTP client, request shaping, and the typed data models for ESPN.
The Client talks to site.api.espn.com, ESPN's unofficial public API. No API key is required. It sets a real User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx).
Index ¶
- Constants
- type Article
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) ListNews(ctx context.Context, sport, league string, limit int) ([]*Article, error)
- func (c *Client) ListSchedule(ctx context.Context, sport, league string) ([]*Game, error)
- func (c *Client) ListScores(ctx context.Context, sport, league string) ([]*Game, error)
- func (c *Client) ListStandings(ctx context.Context, sport, league string) ([]*Standing, error)
- func (c *Client) ListTeams(ctx context.Context, sport, league string) ([]*Team, error)
- type Config
- type Domain
- type Game
- type Standing
- type Team
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "espn-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies this client to ESPN.
const Host = "site.api.espn.com"
Host is the ESPN API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Article ¶
type Article struct {
Headline string `json:"headline"`
Description string `json:"description"`
Byline string `json:"byline,omitempty"`
PublishedDate string `json:"published_date"`
Premium bool `json:"premium"`
WebURL string `json:"web_url,omitempty"`
ImageURL string `json:"image_url,omitempty"`
}
Article is one news article.
type Client ¶
type Client struct {
HTTP *http.Client
BaseURL string
UserAgent string
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the ESPN API over HTTP.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client settings. The body is read and closed here.
func (*Client) ListSchedule ¶
ListSchedule fetches the schedule (same endpoint as scoreboard).
func (*Client) ListScores ¶
ListScores fetches current/recent scoreboard for the given sport/league.
func (*Client) ListStandings ¶
ListStandings fetches current standings for the given sport/league.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds the client settings.
type Domain ¶
type Domain struct{}
Domain is the ESPN driver. It carries no state; the per-run client is built by the factory Register hands kit.
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 {
ID string `json:"id"`
Date string `json:"date"`
ShortName string `json:"short_name"`
HomeTeam string `json:"home_team"`
HomeScore string `json:"home_score"`
AwayTeam string `json:"away_team"`
AwayScore string `json:"away_score"`
Status string `json:"status"`
Season int `json:"season"`
}
Game is one scoreboard entry.
type Standing ¶
type Standing struct {
Team string `json:"team"`
Wins float64 `json:"wins"`
Losses float64 `json:"losses"`
Ties float64 `json:"ties"`
WinPct string `json:"win_pct"`
Division string `json:"division"`
Conference string `json:"conference"`
}
Standing is one team's standing in the league.