traincat

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

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

Go to latest
Published: Dec 8, 2017 License: GPL-3.0 Imports: 7 Imported by: 12

README

Client train.cat

Go Report Card

Documentation

Index

Constants

View Source
const (
	ActionTypeTelegram  = "telegram"
	ActionTypeMessenger = "messenger"
)

Type of action available

View Source
const (
	EmbeddedItems = "items"
	LinkFirst     = "first"
	LinkLast      = "last"
	LinkPrevious  = "previous"
	LinkNext      = "next"
)

All keys can be found in hateoas collection

View Source
const (
	EndpointLogin = "/login"

	// Station
	EndpointStations = "/stations"
	EndpointStation  = EndpointStations + "/%d"

	// Trip
	EndpointTrips = "/trips"
	EndpointTrip  = EndpointTrips + "/%d"

	EndpointStationStopsTime = EndpointStation + stopsTime

	// Alerts
	EndpointAlerts        = "/alerts"
	EndpointStationAlerts = EndpointStation + stopTime + EndpointAlerts

	// Action
	EndpointActions = "/actions"
)

List of endpoint used by the client

View Source
const URL = "https://api.train.cat"

URL of the API

Variables

View Source
var (
	ErrFirstPage = errors.New("no previous page")
	ErrLastPage  = errors.New("no next page")
)

Error relevant to collection

Functions

func BuildURI

func BuildURI(endpoint string, a ...interface{}) string

BuildURI return URI formatted

func Int

func Int(i int) *int

Int return pointer to int

func SetConfig

func SetConfig(c Config)

SetConfig apply the config to the current client

func String

func String(s string) *string

String return pointer to string

Types

type Action

type Action struct {
	Entity
	Type string            `json:"type"`
	Data map[string]string `json:"data"`
	Hateoas
}

Action output from the API

func PostAction

func PostAction(i ActionInput) (*Action, error)

PostAction add nex action to the API

type ActionInput

type ActionInput struct {
	Type string            `json:"type"`
	Data map[string]string `json:"data"`
}

ActionInput for the API

type Alert

type Alert struct {
	Entity
	ActionID uint `json:"action_id"`
	Hateoas
}

Alert output from the API

func CGetAllAlerts

func CGetAllAlerts(f *filters.Alert) ([]Alert, error)

CGetAllAlerts get all pages and return all alerts

func PostAlert

func PostAlert(stationID int, stopTimeID uint, i AlertInput) (*Alert, error)

PostAlert add new alert to the API

type AlertInput

type AlertInput struct {
	ActionID uint `json:"action_id"`
}

AlertInput for the API

type Auth

type Auth struct {
	Username string
	Password string
	// contains filtered or unexported fields
}

Auth structure for log the user

type Collection

type Collection struct {
	Page  int `json:"page"`
	Limit int `json:"limit"`
	Pages int `json:"pages"`
	Total int `json:"total"`
	Hateoas
}

Collection represent structure return by the API

func (*Collection) First

func (c *Collection) First() error

First load the first page

func (*Collection) IsFirstPage

func (c *Collection) IsFirstPage() bool

IsFirstPage return true if collection is currently on the first page

func (*Collection) IsLastPage

func (c *Collection) IsLastPage() bool

IsLastPage return true if collection is currently on the last page

func (*Collection) Last

func (c *Collection) Last() error

Last load the last page

func (*Collection) Next

func (c *Collection) Next() error

Next load next page

func (*Collection) Previous

func (c *Collection) Previous() error

Previous load previous page

type Config

type Config struct {
	Host  string
	Auth  Auth
	Debug bool
}

Config used by the client for call the API

type Embedded

type Embedded map[string]json.RawMessage

Embedded alias to map[string]json.RawMessage

func (*Embedded) Get

func (e *Embedded) Get(key string, s interface{}) error

Get one value from _embedded key

type Entity

type Entity struct {
	ID uint `json:"id"`
}

Entity group all fields available in all entities return by the API

type Hateoas

type Hateoas struct {
	Embedded Embedded        `json:"_embedded"`
	Links    map[string]Link `json:"_links"`
}

Hateoas structure sent by the API

type Link struct {
	Href string `json:"href"`
}

Link structure sent by the API

type Station

type Station struct {
	Entity
	Name       string `json:"name"`
	UIC        string `json:"uic"`
	IsRealTime bool   `json:"is_realtime"`
	Hateoas
}

Station output of the API

func CGetAllStations

func CGetAllStations(f *filters.Station) ([]Station, error)

CGetAllStations get all pages and return all stations

func GetStation

func GetStation(stationID int) (*Station, error)

GetStation return one station

type StopInput

type StopInput struct {
	Schedule string `json:"schedule"`
	IsWeek   bool   `json:"is_week"`
}

StopInput for the API

type StopTime

type StopTime struct {
	Entity
	Schedule string `json:"schedule"`
	Hateoas
}

StopTime output of the API

func CGetStopsTime

func CGetStopsTime(stationID uint, f *filters.StopTime) ([]StopTime, error)

CGetStops return all stopsTime available for one station

func (StopTime) GetStation

func (st StopTime) GetStation() (*Station, error)

GetStation return station associate

func (StopTime) GetTerminus

func (st StopTime) GetTerminus() (*Station, error)

GetTerminus return terminus of the trip

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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