Documentation
¶
Overview ¶
Package tfl is the library behind the tfl command line: the HTTP client, request shaping, and the typed data models for the Transport for London Unified API (api.tfl.gov.uk).
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
- type AirForecast
- type AirQuality
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetAirQuality(ctx context.Context) (*AirQuality, error)
- func (c *Client) GetDisruptions(ctx context.Context, mode string) ([]*Disruption, error)
- func (c *Client) GetJourneys(ctx context.Context, from, to, mode string) ([]*Journey, error)
- func (c *Client) GetLineStatus(ctx context.Context, mode string) ([]*LineStatus, error)
- type Disruption
- type Domain
- type Journey
- type LineStatus
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "tfl-cli/dev (+https://github.com/tamnd/tfl-cli)"
DefaultUserAgent identifies the client to TfL.
const Host = "api.tfl.gov.uk"
Host is the TfL Unified API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AirForecast ¶
type AirForecast struct {
Period string `json:"period"`
ForecastType string `json:"forecast_type"`
ForecastBand string `json:"forecast_band"`
ForecastSummary string `json:"forecast_summary"`
}
AirForecast is one period's air quality forecast.
type AirQuality ¶
type AirQuality struct {
UpdatePeriod string `json:"update_period" kit:"id"`
UpdateFreq string `json:"update_freq"`
ForecastURL string `json:"forecast_url"`
CurrentForecast []AirForecast `json:"current_forecast"`
}
AirQuality is the London air quality data.
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 api.tfl.gov.uk over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetAirQuality ¶
func (c *Client) GetAirQuality(ctx context.Context) (*AirQuality, error)
GetAirQuality fetches the London air quality data.
func (*Client) GetDisruptions ¶
GetDisruptions fetches active disruptions for the given mode.
func (*Client) GetJourneys ¶
GetJourneys fetches journey options between two points.
func (*Client) GetLineStatus ¶
GetLineStatus fetches line statuses for the given mode. mode can be "tube", "bus", "dlr", "overground", "elizabeth-line", or "all".
type Disruption ¶
type Disruption struct {
Category string `json:"category" kit:"id"`
Type string `json:"type"`
Description string `json:"description"`
CreatedTime string `json:"created_time"`
ClosureText string `json:"closure_text"`
}
Disruption is an active service disruption on the TfL network.
type Domain ¶
type Domain struct{}
Domain is the TfL driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into (type, id). A NaPTAN ID like "940GZZLUASL" is classified as "stop"; a line id like "jubilee" is classified as "line".
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.