Documentation
¶
Overview ¶
Package chesscom is the library behind the chesscom command line: the HTTP client, request shaping, and the typed data models for Chess.com.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.
Index ¶
- Constants
- type Client
- func (c *Client) GetCountry(ctx context.Context, code string) (*Country, error)
- func (c *Client) GetGames(ctx context.Context, username string, year, month, limit int) ([]Game, error)
- func (c *Client) GetLeaderboard(ctx context.Context, leaderType string) ([]LeaderEntry, error)
- func (c *Client) GetPage(ctx context.Context, p string) (*Page, error)
- func (c *Client) GetPlayer(ctx context.Context, username string) (*Player, error)
- func (c *Client) GetStats(ctx context.Context, username string) (*PlayerStats, error)
- func (c *Client) PageLinks(ctx context.Context, p string, limit int) ([]*Page, error)
- type Config
- type Country
- type Domain
- type Game
- type LeaderEntry
- type Page
- type Player
- type PlayerStats
Constants ¶
const BaseURL = "https://" + Host + "/pub"
BaseURL is the root every request is built from.
const DefaultUserAgent = "chesscom-cli/0.1.0 (github.com/tamnd/chesscom-cli)"
DefaultUserAgent identifies the client to Chess.com.
const Host = "api.chess.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to Chess.com over HTTP.
func (*Client) GetCountry ¶
GetCountry fetches country info by ISO code.
func (*Client) GetGames ¶
func (c *Client) GetGames(ctx context.Context, username string, year, month, limit int) ([]Game, error)
GetGames fetches games for a player in a given month.
func (*Client) GetLeaderboard ¶
GetLeaderboard fetches leaderboard entries for the given type.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunables for the client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for the Chess.com API.
type Domain ¶
type Domain struct{}
Domain is the chesscom 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 {
URL string `json:"url"`
TimeControl string `json:"time_control"`
EndTime int64 `json:"end_time"`
WhiteUsername string `json:"white_username"`
BlackUsername string `json:"black_username"`
WhiteResult string `json:"white_result"`
BlackResult string `json:"black_result"`
WhiteRating int `json:"white_rating"`
BlackRating int `json:"black_rating"`
PGN string `json:"pgn,omitempty"`
}
Game is one Chess.com game.
type LeaderEntry ¶
type LeaderEntry struct {
Rank int `json:"rank"`
Username string `json:"username"`
Score int `json:"score"`
Title string `json:"title,omitempty"`
CountryCode string `json:"country_code,omitempty"`
URL string `json:"url,omitempty"`
}
LeaderEntry is one entry from a Chess.com leaderboard.
type Page ¶
type Page struct {
ID string `json:"id" kit:"id"`
URL string `json:"url"`
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty" kit:"body"`
}
Page is used by the kit domain driver as the URI-addressable resource.
type Player ¶
type Player struct {
Username string `json:"username"`
Title string `json:"title,omitempty"`
URL string `json:"url"`
CountryCode string `json:"country_code,omitempty"`
Location string `json:"location,omitempty"`
Followers int `json:"followers"`
PlayerID int `json:"player_id"`
Status string `json:"status,omitempty"`
Joined int64 `json:"joined,omitempty"`
LastOnline int64 `json:"last_online,omitempty"`
}
Player is a Chess.com player profile.
type PlayerStats ¶
type PlayerStats struct {
Username string `json:"username"`
BulletRating int `json:"bullet_rating,omitempty"`
BlitzRating int `json:"blitz_rating,omitempty"`
RapidRating int `json:"rapid_rating,omitempty"`
DailyRating int `json:"daily_rating,omitempty"`
BulletWins int `json:"bullet_wins,omitempty"`
BulletLosses int `json:"bullet_losses,omitempty"`
BulletDraws int `json:"bullet_draws,omitempty"`
BlitzWins int `json:"blitz_wins,omitempty"`
BlitzLosses int `json:"blitz_losses,omitempty"`
BlitzDraws int `json:"blitz_draws,omitempty"`
RapidWins int `json:"rapid_wins,omitempty"`
RapidLosses int `json:"rapid_losses,omitempty"`
RapidDraws int `json:"rapid_draws,omitempty"`
}
PlayerStats holds rating info for a Chess.com player.