speedrun

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package speedrun is the library behind the speedrun command line: the HTTP client, request shaping, and typed data models for speedrun.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

View Source
const BaseURL = "https://www.speedrun.com/api/v1"

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "speedrun-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies this client honestly.

View Source
const Host = "www.speedrun.com"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	WebLink string `json:"weblink"`
	Type    string `json:"type"`
}

Category is a single run category for a game.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   string
	// Rate is the minimum gap between requests.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to speedrun.com API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

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

Get fetches a URL and returns the body bytes. Paces and retries automatically.

func (*Client) GetLeaderboard

func (c *Client) GetLeaderboard(ctx context.Context, gameID, categoryID string, top int) ([]*LeaderboardEntry, error)

GetLeaderboard fetches the leaderboard for a game and category.

func (*Client) ListCategories

func (c *Client) ListCategories(ctx context.Context, gameID string) ([]*Category, error)

ListCategories fetches all categories for a game.

func (*Client) ListGames

func (c *Client) ListGames(ctx context.Context, search string, limit int) ([]*Game, error)

ListGames searches for games by name (empty search returns recent games).

func (*Client) ListRuns

func (c *Client) ListRuns(ctx context.Context, gameID string, limit int) ([]*Run, error)

ListRuns fetches recent verified runs, optionally filtered by game ID.

type Domain

type Domain struct{}

Domain is the speedrun.com 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, hostnames, and binary identity.

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 {
	ID       string `json:"id"`
	Name     string `json:"name"`
	WebLink  string `json:"weblink"`
	Released int    `json:"released"`
}

Game is a single speedrun.com game record.

type LeaderboardEntry

type LeaderboardEntry struct {
	Place       int     `json:"place"`
	RunID       string  `json:"run_id"`
	PrimaryTime float64 `json:"primary_time"`
	PlayerID    string  `json:"player_id"`
}

LeaderboardEntry is a single entry in a game leaderboard.

type Run

type Run struct {
	ID          string  `json:"id"`
	WebLink     string  `json:"weblink"`
	Game        string  `json:"game"`
	Category    string  `json:"category"`
	Status      string  `json:"status"`
	PrimaryTime float64 `json:"primary_time"`
	Date        string  `json:"date"`
}

Run is a single speedrun record.

Jump to

Keyboard shortcuts

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