gbfs

package module
v0.0.0-...-dbe8d82 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 10 Imported by: 6

README

gbfs-go

What is GBFS

The General Bikeshare Feed Specification, known as GBFS, is the open data standard for bikeshare. GBFS makes real-time data feeds in a uniform format publicly available online, with an emphasis on findability. GBFS is intended to make information publicly available online; therefore information that is personally identifiable is not currently and will not become part of the core specification.

What is gbfs-go

gbfs-go is a Go library that aimed to simplify reading and writing GBFS data, it provides Go structures and HTTP-client wrapper.

Examples

Try examples:

go run examples/system_information/main.go

License

MIT License

Keep in mind that data feeds may have a different license (like CC0-1.0, CC-BY-4.0, etc).

Documentation

Index

Constants

View Source
const PropulsionTypeCombustion = "combustion"
View Source
const PropulsionTypeElectric = "electric"
View Source
const PropulsionTypeElectricAssist = "electric_assist"
View Source
const PropulsionTypeHuman = "human"
View Source
const SystemsNABSA = "https://github.com/NABSA/gbfs/raw/master/systems.csv"

North American Bike Share Association URL to systems.csv See https://github.com/NABSA/gbfs#systems-implementing-gbfs

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID          ID          `json:"alert_id"`
	Type        AlertType   `json:"type"`
	Times       []AlertTime `json:"times,omitempty"`
	StationIDs  []string    `json:"station_ids,omitempty"`
	RegionIDs   []string    `json:"region_ids,omitempty"`
	URL         string      `json:"url,omitempty"`
	Summary     string      `json:"summary"`
	Description string      `json:"description,omitempty"`
	LastUpdated Timestamp   `json:"last_updated,omitempty"`
}

type AlertTime

type AlertTime struct {
	Start Timestamp `json:"start"`
	End   Timestamp `json:"end,omitempty"`
}

type AlertType

type AlertType string
const AlertOther AlertType = "OTHER"
const AlertStationClosure AlertType = "STATION_CLOSURE"
const AlertStationMove AlertType = "STATION_MOVE"
const AlertSystemClosure AlertType = "SYSTEM_CLOSURE"

type Bool

type Bool bool

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) (err error)

type Calendar

type Calendar struct {
	StartMonth uint16 `json:"start_month"`
	StartDay   uint16 `json:"start_day"`
	StartYear  uint16 `json:"start_year,omitempty"`
	EndMonth   uint16 `json:"end_month"`
	EndDay     uint16 `json:"end_day"`
	EndYear    uint16 `json:"end_year,omitempty"`
}

type Capacity

type Capacity map[string]int

type Client

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

Client represents abstraction on top of all GBFS operations

func NewClient

func NewClient(userAgent string, timeout time.Duration) *Client

NewClient creates new client

func (*Client) LoadFreeBikeStatus

func (c *Client) LoadFreeBikeStatus(url string) (*FreeBikeStatusResponse, error)

func (*Client) LoadGBFS

func (c *Client) LoadGBFS(url string) (*GBFSResponse, error)

func (*Client) LoadGBFSVersions

func (c *Client) LoadGBFSVersions(url string) (*VersionsResponse, error)

func (*Client) LoadStationInformation

func (c *Client) LoadStationInformation(url string) (*StationInformationResponse, error)

func (*Client) LoadStationStatus

func (c *Client) LoadStationStatus(url string) (*StationStatusResponse, error)

func (*Client) LoadSystemAlerts

func (c *Client) LoadSystemAlerts(url string) (*SystemAlertsResponse, error)

func (*Client) LoadSystemCalendar

func (c *Client) LoadSystemCalendar(url string) (*SystemCalendarResponse, error)

func (*Client) LoadSystemHours

func (c *Client) LoadSystemHours(url string) (*SystemHoursResponse, error)

func (*Client) LoadSystemInformation

func (c *Client) LoadSystemInformation(url string) (*SystemInformationResponse, error)

func (*Client) LoadSystemPricingPlans

func (c *Client) LoadSystemPricingPlans(url string) (*SystemPricingPlansResponse, error)

func (*Client) LoadSystemRegions

func (c *Client) LoadSystemRegions(url string) (*SystemRegionsResponse, error)

func (*Client) LoadSystems

func (c *Client) LoadSystems(url string) ([]System, error)

LoadSystem gets URL to systems.csv file and returns parsed systems

func (*Client) LoadVehicleTypes

func (c *Client) LoadVehicleTypes(url string) (*VehicleTypesResponse, error)

type Clock

type Clock time.Time

func (Clock) MarshalJSON

func (clock Clock) MarshalJSON() ([]byte, error)

func (*Clock) String

func (clock *Clock) String() string

func (*Clock) UnmarshalJSON

func (clock *Clock) UnmarshalJSON(input []byte) error

type DataFeeds

type DataFeeds struct {
	Feeds []Feed `json:"feeds"`
}

func (*DataFeeds) GetFeed

func (df *DataFeeds) GetFeed(name string) (*Feed, error)

type Date

type Date time.Time

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (*Date) String

func (d *Date) String() string

func (Date) Time

func (d Date) Time() time.Time

func (Date) Unix

func (d Date) Unix() int64

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(input []byte) error

type Feed

type Feed struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

type FormFactor

type FormFactor string
const FormFactorBicycle FormFactor = "bicycle"
const FormFactorCar FormFactor = "car"
const FormFactorMoped FormFactor = "moped"
const FormFactorOther FormFactor = "other"
const FormFactorScooter FormFactor = "scooter"

type FreeBikeStatus

type FreeBikeStatus struct {
	BikeID             ID         `json:"bike_id"`
	SystemID           ID         `json:"system_id"` // added in v3.0-RC
	Lat                float64    `json:"lat"`
	Lon                float64    `json:"lon"`
	IsReserved         Bool       `json:"is_reserved"`
	IsDisabled         Bool       `json:"is_disabled"`
	RentalURIs         RentalURIs `json:"rental_uris"`          // added in v1.1
	VehicleTypeID      ID         `json:"vehicle_type_id"`      // added in v2.1-RC
	LastReported       Timestamp  `json:"last_reported"`        // added in v2.1-RC
	CurrentRangeMeters float64    `json:"current_range_meters"` // added in v2.1-RC
	StationID          ID         `json:"station_id"`           // added in v2.1-RC
	PricingPlanID      ID         `json:"pricing_plan_id"`      // added in v2.1-RC
}

type FreeBikeStatusData

type FreeBikeStatusData struct {
	Bikes []FreeBikeStatus `json:"bikes"`
}

type FreeBikeStatusResponse

type FreeBikeStatusResponse struct {
	Header
	Data FreeBikeStatusData `json:"data"`
}

type GBFSResponse

type GBFSResponse struct {
	Header
	Data LanguageFeeds `json:"data"`
}

GBFSResponse represent a single system or geographic area in which vehicles are operated.

type Header struct {
	LastUpdated Timestamp `json:"last_updated"`
	TTL         int       `json:"ttl"`
	Version     string    `json:"version"` // added in v1.1
}

Every JSON file presented in the specification contains the same common header information at the top level of the JSON response object.

type ID

type ID string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) (err error)

type LanguageFeeds

type LanguageFeeds map[string]DataFeeds

func (LanguageFeeds) GetDataFeeds

func (lf LanguageFeeds) GetDataFeeds(language string) (*DataFeeds, error)

func (*LanguageFeeds) UnmarshalJSON

func (lf *LanguageFeeds) UnmarshalJSON(data []byte) error

type Plan

type Plan struct {
	ID            ID        `json:"plan_id"`
	URL           string    `json:"url,omitempty"`
	Name          string    `json:"name"`
	Currency      string    `json:"currency"`
	Price         Price     `json:"price"`
	IsTaxable     Bool      `json:"is_taxable"`
	Description   string    `json:"description"`
	PerKmPricing  []Pricing `json:"per_km_pricing,omitempty"`  // added in v2.1-RC2
	PerMinPricing []Pricing `json:"per_min_pricing,omitempty"` // added in v2.1-RC2
}

type Price

type Price interface{}

type Pricing

type Pricing struct {
	Start    uint16  `json:"start"`
	Rate     float64 `json:"rate"`
	Interval uint16  `json:"intercal"`
	End      uint16  `json:"end,omitempty"`
}

type PropulsionType

type PropulsionType string

type Region

type Region struct {
	ID   ID     `json:"region_id"`
	Name string `json:"name"`
}

type RentalApps

type RentalApps struct {
	Android RentalAppsStore `json:"android,omitempty"`
	IOS     RentalAppsStore `json:"ios,omitempty"`
}

type RentalAppsStore

type RentalAppsStore struct {
	StoreURI     string `json:"store_uri"`
	DiscoveryURI string `json:"discovery_uri"`
}

type RentalHours

type RentalHours struct {
	UserTypes []UserType `json:"user_types"`
	Days      []Weekday  `json:"days"`
	StartTime Clock      `json:"start_time"`
	EndTime   Clock      `json:"end_time"`
}

type RentalMethod

type RentalMethod string
const RentalMethodAccountNumber RentalMethod = "ACCOUNTNUMBER"
const RentalMethodAndroidPay RentalMethod = "ANDROIDPAY"
const RentalMethodApplePay RentalMethod = "APPLEPAY"
const RentalMethodCreditCard RentalMethod = "CREDITCARD"
const RentalMethodKey RentalMethod = "KEY"
const RentalMethodPayPass RentalMethod = "PAYPASS"
const RentalMethodPhone RentalMethod = "PHONE"
const RentalMethodTransitCard RentalMethod = "TRANSITCARD"

type RentalURIs

type RentalURIs struct {
	Android string `json:"android,omitempty"`
	IOS     string `json:"ios,omitempty"`
	Web     string `json:"web,omitempty"`
}

type StationInformation

type StationInformation struct {
	ID                  ID             `json:"station_id"`
	Name                string         `json:"name"`
	ShortName           string         `json:"short_name,omitempty"`
	Lat                 float64        `json:"lat"`
	Lon                 float64        `json:"lon"`
	Address             string         `json:"address,omitempty"`
	CrossStreet         string         `json:"cross_street,omitempty"`
	RegionID            ID             `json:"region_id,omitempty"`
	PostCode            string         `json:"post_code,omitempty"`
	RentalMethods       []RentalMethod `json:"rental_methods,omitempty"`
	IsVirtualStation    *bool          `json:"is_virtual_station,omitempty"` // added in v2.1-RC
	StationArea         interface{}    `json:"station_area,omitempty"`       // added in v2.1-RC
	Capacity            int            `json:"capacity,omitempty"`
	VehicleCapacity     Capacity       `json:"vehicle_capacity"`                // added in v2.1-RC
	IsValetStation      *bool          `json:"is_valet_station,omitempty"`      // added in v2.1-RC
	RentalURIs          RentalURIs     `json:"rental_uris,omitempty"`           // added in v1.1
	VehicleTypeCapacity Capacity       `json:"vehicle_type_capacity,omitempty"` // added in v2.1
}

type StationInformationData

type StationInformationData struct {
	Stations []StationInformation `json:"stations"`
}

type StationInformationResponse

type StationInformationResponse struct {
	Header
	Data StationInformationData `json:"data"`
}

type StationStatus

type StationStatus struct {
	ID                    ID                    `json:"station_id"`
	NumBikesAvailable     uint                  `json:"num_bikes_available"`
	NumBikesDisabled      uint                  `json:"num_bikes_disabled,omitempty"`
	NumDocksAvailable     uint                  `json:"num_docks_available,omitempty"`
	IsInstalled           Bool                  `json:"is_installed"`
	IsRenting             Bool                  `json:"is_renting"`
	IsReturning           Bool                  `json:"is_returning"`
	LastReported          Timestamp             `json:"last_reported"`
	VehicleTypesAvailable []VehicleAvailability `json:"vehicle_types_available,omitempty"` // added in v2.1-RC
	VehicleDocksAvailable []VehicleAvailability `json:"vehicle_docks_available"`           // added in v2.1-RC
}

type StationStatusData

type StationStatusData struct {
	Stations []StationStatus `json:"stations"`
}

type StationStatusResponse

type StationStatusResponse struct {
	Header
	Data StationStatusData `json:"data"`
}

type System

type System struct {
	ID               string `json:"id" db:"id"`
	CountryCode      string `json:"country_code" db:"country_code"`
	Name             string `json:"name" db:"name"`
	Location         string `json:"location" db:"location"`
	URL              string `json:"url" db:"url"`
	AutoDiscoveryURL string `json:"auto_discovery_url" db:"auto_discovery_url"`
}

System represents system publishing GBFS feeds

func ParseSystemsCSV

func ParseSystemsCSV(reader io.Reader) ([]System, error)

type SystemAlertsData

type SystemAlertsData struct {
	Alerts []Alert `json:"alerts"`
}

type SystemAlertsResponse

type SystemAlertsResponse struct {
	Header
	Data SystemAlertsData `json:"data"`
}

type SystemCalendarData

type SystemCalendarData struct {
	Calendars []Calendar `json:"calendars"`
}

type SystemCalendarResponse

type SystemCalendarResponse struct {
	Header
	Data SystemCalendarData `json:"data"`
}

type SystemHoursData

type SystemHoursData struct {
	RentalHours []RentalHours `json:"rental_hours"`
}

type SystemHoursResponse

type SystemHoursResponse struct {
	Header
	Data SystemHoursData `json:"data"`
}

type SystemInformation

type SystemInformation struct {
	SystemID                    ID         `json:"system_id"`
	Language                    string     `json:"language"`
	Name                        string     `json:"name"`
	ShortName                   string     `json:"short_name,omitempty"`
	Operator                    string     `json:"operator,omitempty"`
	URL                         string     `json:"url,omitempty"`
	PurchaseURL                 string     `json:"purchase_url,omitempty"`
	StartDate                   Date       `json:"start_date,omitempty"`
	PhoneNumber                 string     `json:"phone_number,omitempty"`
	Email                       string     `json:"email,omitempty"`
	FeedContactEmail            string     `json:"feed_contact_email,omitempty"` // added in v1.1
	Timezone                    string     `json:"timezone"`
	LicenseID                   string     `json:"license_id,omitempty"`
	LicenseURL                  string     `json:"license_url,omitempty"`
	AttributionOrganizationName string     `json:"attribution_organization_name,omitempty"`
	AttributionURL              string     `json:"attribution_url,omitempty"`
	RentalApps                  RentalApps `json:"rental_apps,omitempty"` // added in v1.1
}

type SystemInformationResponse

type SystemInformationResponse struct {
	Header
	Data SystemInformation `json:"data"`
}

type SystemPricingPlans

type SystemPricingPlans struct {
	Plans []Plan `json:"plans"`
}

type SystemPricingPlansResponse

type SystemPricingPlansResponse struct {
	Header
	Data SystemPricingPlans `json:"data"`
}

type SystemRegions

type SystemRegions struct {
	Regions []Region `json:"regions"`
}

type SystemRegionsResponse

type SystemRegionsResponse struct {
	Header
	Data SystemRegions `json:"data"`
}

type Timestamp

type Timestamp time.Time

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

func (Timestamp) String

func (t Timestamp) String() string

func (Timestamp) Time

func (t Timestamp) Time() time.Time

func (Timestamp) Unix

func (t Timestamp) Unix() int64

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) (err error)

type UserType

type UserType string
const UserTypeMember UserType = "member"
const UserTypeNonMember UserType = "nonmember"

type VehicleAvailability

type VehicleAvailability struct {
	VehicleTypeID ID   `json:"vehicle_type_id"`
	Count         uint `json:"count"`
}

type VehicleType

type VehicleType struct {
	VehicleTypeID  ID             `json:"vehicle_type_id"`
	FormFactor     FormFactor     `json:"form_factor"`
	PropulsionType PropulsionType `json:"propulsion_type"`
	MaxRangeMeters float64        `json:"max_range_meters,omitempty"`
	Name           string         `json:"name,omitempty"`
}

type VehicleTypesData

type VehicleTypesData struct {
	VehicleTypes []VehicleType `json:"vehicle_types"`
}

type VehicleTypesResponse

type VehicleTypesResponse struct {
	Header
	Data VehicleTypesData `json:"data"`
}

type Version

type Version struct {
	Version string `json:"version"`
	URL     string `json:"url"`
}

type VersionsData

type VersionsData struct {
	Versions []Version `json:"versions"`
}

type VersionsResponse

type VersionsResponse struct {
	Header
	Data VersionsData `json:"data"`
}

type Weekday

type Weekday time.Weekday

func (*Weekday) UnmarshalJSON

func (w *Weekday) UnmarshalJSON(b []byte) (err error)

Jump to

Keyboard shortcuts

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