gira

package
v0.0.0-...-74db963 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoActiveTrip = fmt.Errorf("gira: no active trip")

	ErrAlreadyHasActiveTrip     = fmt.Errorf("gira: already has active trip")
	ErrBikeAlreadyReserved      = fmt.Errorf("gira: bike already reserved")
	ErrNotEnoughBalance         = fmt.Errorf("gira: not enough balance")
	ErrTripIntervalLimit        = fmt.Errorf("gira: trip interval limit")
	ErrHasNoActiveSubscriptions = fmt.Errorf("gira: has no active subscriptions")
	ErrNoServiceStatusFound     = fmt.Errorf("gira: no service status found")
	ErrBikeAlreadyInTrip        = fmt.Errorf("gira: bike already in trip")
)
View Source
var (
	AssetStatusActive AssetStatus = "active"

	BikeTypeElectric     BikeType = "electric"
	BikeTypeConventional BikeType = "conventional"
)

Functions

func SubscribeActiveTrips

func SubscribeActiveTrips(ctx context.Context, ts oauth2.TokenSource) (<-chan TripUpdate, error)

func SubscribeServerDate

func SubscribeServerDate(ctx context.Context, ts oauth2.TokenSource) (<-chan time.Time, error)

Types

type AssetStatus

type AssetStatus string

type Bike

type Bike struct {
	Code   BikeCode
	Serial BikeSerial
	Status AssetStatus
	Parent DockCode

	Name    string
	Type    BikeType
	Battery string

	// set only if returned from GetStationDocks
	DockNumber int
}

func BikeFromCallbackData

func BikeFromCallbackData(data string) (b Bike, err error)

BikeFromCallbackData parses the callback data and returns the bike.

func (Bike) CallbackData

func (b Bike) CallbackData() string

CallbackData returns the callback data for the bike. It contains enough data to show info about bike.

func (Bike) Number

func (b Bike) Number() int

func (Bike) PrettyBattery

func (b Bike) PrettyBattery() string

func (Bike) PrettyString

func (b Bike) PrettyString() string

func (Bike) TextBattery

func (b Bike) TextBattery() string

func (Bike) TextString

func (b Bike) TextString() string

type BikeCode

type BikeCode Code

type BikeSerial

type BikeSerial Serial

type BikeType

type BikeType string

type Client

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

func New

func New(httpc *http.Client) *Client

func (*Client) CancelBikeReserve

func (c *Client) CancelBikeReserve(ctx context.Context) (bool, error)

func (*Client) GetActiveTrip

func (c *Client) GetActiveTrip(ctx context.Context) (Trip, error)

func (*Client) GetClientInfo

func (c *Client) GetClientInfo(ctx context.Context) (ClientInfo, error)

func (*Client) GetStationCached

func (c *Client) GetStationCached(ctx context.Context, serial StationSerial) (Station, error)

GetStationCached returns a station from the cache if it exists, otherwise it calls GetStation. This is useful to avoid calling GetStations multiple times if up-to-date data like free dock count is not required.

func (*Client) GetStationDocks

func (c *Client) GetStationDocks(ctx context.Context, id StationSerial) (Docks, error)

func (*Client) GetStations

func (c *Client) GetStations(ctx context.Context) ([]Station, error)

func (*Client) GetTrip

func (c *Client) GetTrip(ctx context.Context, code TripCode) (Trip, error)

func (*Client) GetTripHistory

func (c *Client) GetTripHistory(ctx context.Context, page, pageSize int) ([]Trip, error)

func (*Client) GetUnratedTrips

func (c *Client) GetUnratedTrips(ctx context.Context, page, pageSize int) ([]Trip, error)

func (*Client) PayTripWithMoney

func (c *Client) PayTripWithMoney(ctx context.Context, id TripCode) (int, error)

func (*Client) PayTripWithPoints

func (c *Client) PayTripWithPoints(ctx context.Context, id TripCode) (int, error)

func (*Client) RateTrip

func (c *Client) RateTrip(ctx context.Context, code TripCode, rating TripRating) (bool, error)

func (*Client) ReserveBike

func (c *Client) ReserveBike(ctx context.Context, id BikeSerial) (bool, error)

func (*Client) StartTrip

func (c *Client) StartTrip(ctx context.Context) (bool, error)

type ClientInfo

type ClientInfo struct {
	Code    UserCode
	Name    string
	Balance float64
	Bonus   int

	ActiveSubscriptions []ClientSubscription
}

type ClientSubscription

type ClientSubscription struct {
	Code   SubscriptionCode
	User   UserCode
	Client UserCode

	SubscriptionStatus string
	Active             bool
	ActivationDate     time.Time
	ExpirationDate     time.Time

	Subscription            string
	Cost                    float64
	SubscriptionCode        string
	SubscriptionName        string
	SubscriptionDescription string
}

type Code

type Code string

type Dock

type Dock struct {
	Code   DockCode
	Serial DockSerial
	Status AssetStatus
	Parent StationCode

	Number     int
	LedStatus  string
	LockStatus string

	Bike *Bike
}

func (Dock) ButtonString

func (d Dock) ButtonString(isMax bool) string

type DockCode

type DockCode Code

type DockSerial

type DockSerial Serial

type Docks

type Docks []Dock

func (Docks) ConventionalBikesAvailable

func (ds Docks) ConventionalBikesAvailable() int

func (Docks) ElectricBikesAvailable

func (ds Docks) ElectricBikesAvailable() int

func (Docks) FreeDocks

func (ds Docks) FreeDocks() int

type Serial

type Serial string

type Station

type Station struct {
	Code   StationCode
	Serial StationSerial
	Status AssetStatus

	Type        string
	Name        string
	Description string

	Latitude  float64
	Longitude float64

	Docks int
	Bikes int
}

func (Station) Location

func (s Station) Location() string

func (Station) MapTitle

func (s Station) MapTitle() string

func (Station) Number

func (s Station) Number() string

type StationCode

type StationCode Code

type StationContent

type StationContent struct {
	Docks []Dock
}

type StationSerial

type StationSerial Serial

type SubscriptionCode

type SubscriptionCode Code

type Trip

type Trip struct {
	Code       TripCode
	TripStatus string

	User     UserCode
	Client   UserCode
	BikeCode BikeCode
	BikeName string

	StartLocation     StationCode
	EndLocation       StationCode
	StartLocationName string
	EndLocationName   string
	StartDate         time.Time
	EndDate           time.Time
	StartOccupation   float64
	EndOccupation     float64
	EndTripDock       DockCode

	Distance   float64
	Cost       float64
	TotalBonus int
	CostBonus  int

	Rating  int
	Photo   string
	Comment string
}

type TripCode

type TripCode Code

type TripRating

type TripRating struct {
	Rating  int
	Comment string
}

type TripUpdate

type TripUpdate struct {
	Code            TripCode
	Bike            string
	StartDate       time.Time
	EndDate         time.Time
	Cost            float64
	Finished        bool
	Canceled        bool
	CanPayWithMoney bool
	CanUsePoints    bool
	ClientPoints    int
	TripPoints      int
	Period          string
	PeriodTime      string
	Error           int
}

func (TripUpdate) PrettyDuration

func (t TripUpdate) PrettyDuration() string

PrettyDuration returns the duration of the trip in a human-readable format. If the trip is still ongoing, the current time is used as the end time.

type UserCode

type UserCode Code

Jump to

Keyboard shortcuts

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