Documentation ¶
Overview ¶
Package bikepoint implements an HTTP client for TfL's BikePoint Unified API.
Swagger: https://api.tfl.gov.uk/swagger/ui/index.html?url=/swagger/docs/v1#!/BikePoint/BikePoint_GetAll
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Availability ¶
type Availability struct { // Docks is the number of in-service, vacant docks to which a bike can be // returned. It is taken from the `NbEmptyDocks` property. Docks int // Bicycles is the number of in-service, non-electric bikes available for // hire. It is taken from the `NbStandardBikes` property. Bicycles int // EBikes is the number of in-service, electric bikes available for hire. // It is taken from the `NbEBikes` property. EBikes int }
Availability represents the hire and drop-off services available at a station based on its occupancy.
type Client ¶
type Client struct { // Logger will be used to record failed fetch attempts. Logger *slog.Logger // HTTPClient is the client used to make requests to the API. This must be // provided when calling NewClient(). HTTPClient *http.Client // Timeout is the per-attempt request timeout. This can be configured using // WithTimeout(). Timeout time.Duration // AppKey is the TfL Unified API application key to attach to requests in // the `app_key` header. If empty, anonymous access will be used. This can // be configured using WithAppKey(). AppKey string // contains filtered or unexported fields }
Client is used to interact with the BikePoint API. Create instances with NewClient().
We do not implement station filtering here as there would be no point - we'd have to decode the JSON and then delete bits from the output. This is left to the user of the client.
func (*Client) FetchStationAvailabilities ¶
func (c *Client) FetchStationAvailabilities(ctx context.Context) ([]StationAvailability, error)
FetchStationAvailabilities retrieves the latest cycle and dock availability. It will back-off exponentially until the passed context expires. The returned list can be assumed to be sorted by station ID.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption allows customising the client's behaviour during construction with NewClient().
func WithAppKey ¶
func WithAppKey(key string) ClientOption
WithAppKey configures an application key to attach to API calls. This can be obtained from https://api-portal.tfl.gov.uk/, and increases the request limit from 50 to 500 calls per minute.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the per-attempt request timeout. This is 3s by default. The lower of this and the HTTPClient's request timeout will be effective.
type Station ¶
type Station struct { // Name is the human-readable location of the docking point, e.g. // "Stonecutter Street, Holborn". It is taken from the `commonName` field // of the JSON. Name string // Docks indicates the total number of docks at the docking point, // including those out of service. It is taken from the `NbDocks` property // of the JSON. Docks int }
Station contains relatively-stable metadata about a docking point.
type StationAvailability ¶
type StationAvailability struct { Station Availability }
StationAvailability represents the occupancy of bikes at a particular docking station. This could represent the result of a `/BikePoint/{id}` query.
func (*StationAvailability) UnmarshalJSON ¶
func (sa *StationAvailability) UnmarshalJSON(b []byte) error