mbta

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: 12 Imported by: 0

Documentation

Overview

Package mbta is the library behind the mbta command line: the HTTP client, request shaping, and the typed data models for the Massachusetts Bay Transportation Authority public API (api-v3.mbta.com).

The free API requires no key. The Client sets a polite User-Agent, paces requests, and retries transient failures (429 and 5xx) with a capped backoff.

Index

Constants

View Source
const Host = "api-v3.mbta.com"

Host is the MBTA API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID          string `json:"id"`
	Header      string `json:"header"`
	Description string `json:"description,omitempty"`
	Effect      string `json:"effect,omitempty"`
	Lifecycle   string `json:"lifecycle,omitempty"`
	Severity    int    `json:"severity_level,omitempty"`
}

Alert is one service alert.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the MBTA API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Alerts

func (c *Client) Alerts(ctx context.Context, routeID string, limit int) ([]Alert, error)

Alerts returns service alerts for a route.

func (*Client) Predictions

func (c *Client) Predictions(ctx context.Context, routeID string, limit int) ([]Prediction, error)

Predictions returns arrival/departure predictions for a route. It resolves stop names from the included resources.

func (*Client) Routes

func (c *Client) Routes(ctx context.Context, routeTypes string) ([]Route, error)

Routes returns subway/light rail routes. routeTypes is a comma-separated list like "0,1" (0=Light Rail, 1=Subway). Empty means all types.

func (*Client) Stops

func (c *Client) Stops(ctx context.Context, routeID string, limit int) ([]Stop, error)

Stops returns stops on a route.

func (*Client) Vehicles

func (c *Client) Vehicles(ctx context.Context, routeID string, limit int) ([]Vehicle, error)

Vehicles returns live vehicle positions for a route.

type Config

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

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the MBTA API.

type Domain

type Domain struct{}

Domain is the MBTA driver.

func (Domain) Classify

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

Classify turns an input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns 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 Prediction

type Prediction struct {
	ID            string `json:"id"`
	DepartureTime string `json:"departure_time,omitempty"`
	Status        string `json:"status,omitempty"`
	DirectionID   int    `json:"direction_id"`
	StopName      string `json:"stop_name,omitempty"`
}

Prediction is one arrival/departure prediction.

type Route

type Route struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Color    string `json:"color,omitempty"`
	Type     int    `json:"type"`
	TypeName string `json:"type_name,omitempty"`
}

Route is one transit route.

type Stop

type Stop struct {
	ID           string  `json:"id"`
	Name         string  `json:"name"`
	Municipality string  `json:"municipality,omitempty"`
	Latitude     float64 `json:"latitude,omitempty"`
	Longitude    float64 `json:"longitude,omitempty"`
}

Stop is one stop or station on a route.

type Vehicle

type Vehicle struct {
	ID        string  `json:"id"`
	Label     string  `json:"label,omitempty"`
	Status    string  `json:"current_status,omitempty"`
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
	Speed     float64 `json:"speed,omitempty"`
}

Vehicle is one live vehicle position.

Jump to

Keyboard shortcuts

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