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
- type Alert
- type Client
- func (c *Client) Alerts(ctx context.Context, routeID string, limit int) ([]Alert, error)
- func (c *Client) Predictions(ctx context.Context, routeID string, limit int) ([]Prediction, error)
- func (c *Client) Routes(ctx context.Context, routeTypes string) ([]Route, error)
- func (c *Client) Stops(ctx context.Context, routeID string, limit int) ([]Stop, error)
- func (c *Client) Vehicles(ctx context.Context, routeID string, limit int) ([]Vehicle, error)
- type Config
- type Domain
- type Prediction
- type Route
- type Stop
- type Vehicle
Constants ¶
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 (*Client) Predictions ¶
Predictions returns arrival/departure predictions for a route. It resolves stop names from the included resources.
func (*Client) Routes ¶
Routes returns subway/light rail routes. routeTypes is a comma-separated list like "0,1" (0=Light Rail, 1=Subway). Empty means all types.
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) 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 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.