fpl

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 fpl is the library behind the fpl command line: the HTTP client, request shaping, and the typed data models for the Fantasy Premier League public API.

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 API throws under load.

Index

Constants

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

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "fpl/dev (+https://github.com/tamnd/fpl-cli)"

DefaultUserAgent identifies the client to FPL.

View Source
const Host = "fantasy.premierleague.com"

Host is the Fantasy Premier League API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the FPL API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) BootstrapStatic

func (c *Client) BootstrapStatic(ctx context.Context) ([]Player, []Team, []Gameweek, error)

BootstrapStatic fetches the large bootstrap-static payload and returns players, teams, and gameweeks.

func (*Client) Entry

func (c *Client) Entry(ctx context.Context, id int) (*wireEntry, error)

Entry fetches an FPL manager/team entry by ID.

func (*Client) Fixtures

func (c *Client) Fixtures(ctx context.Context, gw int) ([]Fixture, error)

Fixtures fetches fixtures for a given gameweek. It also fetches bootstrap to resolve team IDs to names.

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's settings.

func (*Client) LeagueStandings

func (c *Client) LeagueStandings(ctx context.Context, id int) (string, []StandingEntry, error)

LeagueStandings fetches standings for a classic league by ID.

func (*Client) PlayerSummary

func (c *Client) PlayerSummary(ctx context.Context, id int) ([]PlayerHistory, error)

PlayerSummary fetches the gameweek history for a player by element ID.

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds optional overrides from the kit config.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for FPL.

type Domain

type Domain struct{}

Domain is the fpl driver.

func (Domain) Classify

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

Classify turns an accepted input into (uriType, id). Numeric string → "player"; "gw:" prefix → "gameweek"; "l:" prefix → "league".

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 Fixture

type Fixture struct {
	TeamHome    string `json:"team_home"`
	TeamAway    string `json:"team_away"`
	ScoreHome   int    `json:"score_home"`
	ScoreAway   int    `json:"score_away"`
	Finished    bool   `json:"finished"`
	KickoffTime string `json:"kickoff_time"`
}

Fixture is one match in a gameweek.

type Gameweek

type Gameweek struct {
	ID           int    `kit:"id" json:"id"`
	Name         string `json:"name"`
	DeadlineTime string `json:"deadline_time"`
	Finished     bool   `json:"finished"`
	IsCurrent    bool   `json:"is_current"`
	AverageScore int    `json:"average_score"`
	HighestScore int    `json:"highest_score"`
}

Gameweek is one FPL event.

type Player

type Player struct {
	ID          int     `kit:"id" json:"id"`
	Name        string  `json:"name"`
	FullName    string  `json:"full_name"`
	TeamID      int     `json:"team_id"`
	Price       float64 `json:"price"`
	TotalPoints int     `json:"total_points"`
	Form        string  `json:"form"`
	SelectedBy  string  `json:"selected_by"`
}

Player is one FPL element (player).

type PlayerHistory

type PlayerHistory struct {
	Round       int `json:"round"`
	Points      int `json:"points"`
	Minutes     int `json:"minutes"`
	Goals       int `json:"goals_scored"`
	Assists     int `json:"assists"`
	CleanSheets int `json:"clean_sheets"`
}

PlayerHistory is one gameweek's performance for a player.

type StandingEntry

type StandingEntry struct {
	Rank      int    `json:"rank"`
	EntryName string `json:"entry_name"`
	Manager   string `json:"manager"`
	Total     int    `json:"total"`
}

StandingEntry is one row in a classic league standings table.

type Team

type Team struct {
	ID        int    `kit:"id" json:"id"`
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
	Played    int    `json:"played"`
	Won       int    `json:"won"`
	Drawn     int    `json:"drawn"`
	Lost      int    `json:"lost"`
	Points    int    `json:"points"`
}

Team is one Premier League club.

Jump to

Keyboard shortcuts

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