vbb

package module
v6.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 7 Imported by: 0

README

Go client for Berlin/Brandenburg transport API

A Go client for the VBB API

Usage

Add to your go.mod file:

go get github.com/andrewslotin/vbb

Initialize the API client:

c := vbb.New(vbb.BaseURL, nil)

Documentation

Index

Constants

View Source
const BaseURL = "https://v6.vbb.transport.rest"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a VBB API client

func New

func New(endpoint string, c *http.Client) *Client

New returns a new instance of VBB API client

func (*Client) Arrivals

func (c *Client) Arrivals(stopID string, when time.Time, duration time.Duration, transportTypes TransportationType) ([]Departure, error)

Arrivals returns a list of arrivals for the stop at given time

func (*Client) Departures

func (c *Client) Departures(stopID string, when time.Time, duration time.Duration, transportTypes TransportationType) ([]Departure, error)

Departures returns a list of departures for the stop at given time

func (*Client) Locations

func (c *Client) Locations(query string, locType LocationType, resultsNum int) ([]Location, error)

Locations returns first resultsNum locations matching the query

func (*Client) StopsNearby

func (c *Client) StopsNearby(lat, lng float64, distance, resultsNum int) ([]Location, error)

StopsNearby returns resultsNum stops within distance meters of walking from given location

type Departure

type Departure struct {
	Direction       string
	When            time.Time
	PlannedWhen     time.Time
	Delay           int
	Platform        string
	PlannedPlatform string
	Line            Line
}

Departure represents departure information

type Line

type Line struct {
	Name    string
	Product string
}

Line represents a public transportation line

type Location

type Location struct {
	Type                string
	ID                  string
	Name                string
	Address             string
	Latitude, Longitude float64
	Distance            int
}

Location is a station, stop, POI or an address

func (Location) MarshalJSON

func (loc Location) MarshalJSON() ([]byte, error)

MarshalJSON marshals Location into HAFAS@v6 JSON representation

func (*Location) UnmarshalJSON

func (loc *Location) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals HAFAS@v6 JSON representation into Location

type LocationType

type LocationType uint8

LocationType represents location type

const (
	LocationTypeUnknown LocationType = 0
	LocationTypeStop    LocationType = 1 << iota
	LocationTypeAddress
	LocationTypePOI
	LocationTypeAny = LocationTypeStop | LocationTypeAddress | LocationTypePOI
)

type TransportationType

type TransportationType uint8

TransportationType represents the type transport type

const (
	SuburbanTrain TransportationType = 1<<iota + 1
	Subway
	Tram
	Bus
	Ferry
	ExpressTrain
	RegionalTrain

	UrbanTransport = SuburbanTrain | Subway | Tram | Bus | Ferry | RegionalTrain
	AllTransport   = UrbanTransport | ExpressTrain
)

Jump to

Keyboard shortcuts

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