gbfs

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

Documentation

Overview

Package gbfs is the library behind the gbfs command line: the HTTP client, request shaping, and the typed data models for GBFS (General Bikeshare Feed Specification) feeds.

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

Index

Constants

View Source
const Host = "gbfs.lyft.com"

Host is the primary GBFS host (Citi Bike NYC / Lyft).

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a rate-limited HTTP client for GBFS feeds.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) GetSystemInfo

func (c *Client) GetSystemInfo(ctx context.Context, system string) (*SystemInfo, error)

GetSystemInfo fetches the system_information feed for the given system.

func (*Client) ListStations

func (c *Client) ListStations(ctx context.Context, system string, minBikes int) ([]Station, error)

ListStations fetches station_information and station_status for the given system, joins them by station_id, and filters to stations with at least minBikes bikes available. Pass minBikes=0 to return all stations.

type Config

type Config struct {
	// SystemURLs maps short system IDs to their GBFS base URL.
	SystemURLs map[string]string
	UserAgent  string
	Rate       time.Duration
	Retries    int
	Timeout    time.Duration
}

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for GBFS feeds.

type Domain

type Domain struct{}

Domain is the GBFS driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

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

Classify turns any accepted input into the canonical (type, id). Accepts "bkn", "divvy", "bay", "capital" as system IDs, and "station-<id>" as station references.

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 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 Station

type Station struct {
	ID              string  `json:"id" kit:"id"`
	Name            string  `json:"name"`
	Lat             float64 `json:"lat"`
	Lon             float64 `json:"lon"`
	BikesAvailable  int     `json:"bikes_available"`
	EBikesAvailable int     `json:"ebikes_available"`
	DocksAvailable  int     `json:"docks_available"`
	IsRenting       bool    `json:"is_renting"`
	LastReported    int64   `json:"last_reported"`
}

Station is one bike share station with availability data joined in.

type SystemInfo

type SystemInfo struct {
	ID       string `json:"id" kit:"id"`
	Name     string `json:"name"`
	URL      string `json:"url"`
	Timezone string `json:"timezone"`
	Language string `json:"language"`
	Email    string `json:"email"`
}

SystemInfo describes a GBFS system.

Jump to

Keyboard shortcuts

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