Documentation ¶
Overview ¶
Package sptrans is a Go client library for the SPTrans Olho Vivo API.
Usage:
import "github.com/sergioaugrod/go-sptrans/sptrans"
Authentication:
token = "123456" client = sptrans.NewClient(token) client.Authenticate()
Endpoints:
Lines
// Search by line description or number client.Line.Search("Lapa") client.Line.Search("8000") // Search by line direction client.Line.SearchByDirection("Lapa", 1)
Stops
// Search by stop name or address client.Stop.Search("Afonso") client.Stop.Search("Rua Baltharzar da Veiga") // Search by line id client.Stop.SearchByLine(1273) // Search by corridor id client.Stop.SearchByCorridor(8)
Corridors
// All smart corridors client.Corridor.All()
Companies
// All companies client.Company.All()
Vehicles Position
// All Vehicles Position client.VehiclePosition.All() // Search by line id client.VehiclePosition.SearchByLine(1273) // Search by company id client.VehiclePosition.SearchByCompany(99)
Forecast
// Search by stop id and line id client.Forecast.Search(2003, 2004) // Search by line id client.Forecast.SearchByLine(1273) // Search by stop id client.Forecast.SearchByStop(8)
Index ¶
- type Client
- type Company
- type CompanyOperation
- type CompanyResponse
- type CompanyService
- type Corridor
- type CorridorService
- type ForecastLine
- type ForecastLineResponse
- type ForecastLineStop
- type ForecastResponse
- type ForecastService
- type ForecastStop
- type ForecastVehicle
- type Line
- type LineService
- type Stop
- type StopService
- type VehiclePosition
- type VehiclePositionLine
- type VehiclePositionLineResponse
- type VehiclePositionResponse
- type VehiclePositionService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { BaseURL *url.URL HTTP *http.Client Line *LineService Stop *StopService Corridor *CorridorService Company *CompanyService VehiclePosition *VehiclePositionService Forecast *ForecastService Token string }
Client is a SPTrans client for making Olho Vivo API requests
func (*Client) Authenticate ¶
Authenticate authenticates according to client token
type CompanyOperation ¶ added in v0.2.0
CompanyOperation structure
type CompanyResponse ¶ added in v0.2.0
type CompanyResponse struct { Hour string `json:"hr"` Operations []*CompanyOperation `json:"e"` }
CompanyResponse structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-empresas
type CompanyService ¶ added in v0.2.0
type CompanyService service
CompanyService provide functions to request companies endpoints
func (*CompanyService) All ¶ added in v0.2.0
func (r *CompanyService) All() ([]*CompanyOperation, error)
All returns all companies
type Corridor ¶ added in v0.2.0
Corridor structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-corredores
type CorridorService ¶ added in v0.2.0
type CorridorService service
CorridorService provide functions to request corridors endpoints
func (*CorridorService) All ¶ added in v0.2.0
func (r *CorridorService) All() ([]*Corridor, error)
All returns all smart corridors
type ForecastLine ¶ added in v0.4.0
type ForecastLine struct { FullSign string `json:"c"` Id int64 `json:"cl"` Direction int64 `json:"sl"` DestinationSign string `json:"lt0"` OriginSign string `json:"lt1"` QuantityVehicles int64 `json:"qv"` Vehicles []*ForecastVehicle `json:"vs"` }
ForecastLine is a line structure
type ForecastLineResponse ¶ added in v0.4.0
type ForecastLineResponse struct { Hour string `json:"hr"` Stops []*ForecastLineStop `json:"ps"` }
ForecastLineResponse is a line response structure with hour and a list of stops
type ForecastLineStop ¶ added in v0.4.0
type ForecastLineStop struct { Id int64 `json:"cp"` Name string `json:"np"` Latitude float64 `json:"py"` Longitude float64 `json:"px"` Vehicles []*ForecastVehicle `json:"vs"` }
ForecastLineStop is a line stop structure
type ForecastResponse ¶ added in v0.4.0
type ForecastResponse struct { Hour string `json:"hr"` Stop ForecastStop `json:"p"` }
ForecastResponse structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-previsao
type ForecastService ¶ added in v0.4.0
type ForecastService service
ForecastService provide functions to request forecasts endpoints
func (*ForecastService) Search ¶ added in v0.4.0
func (r *ForecastService) Search(stopId int, lineId int) (ForecastStop, error)
Search performs a search of bus arrivals based on stop id or line id
func (*ForecastService) SearchByLine ¶ added in v0.4.0
func (r *ForecastService) SearchByLine(lineId int) ([]*ForecastLineStop, error)
SearchByLine performs a search of the bus arrivals based on the line id
func (*ForecastService) SearchByStop ¶ added in v0.4.0
func (r *ForecastService) SearchByStop(stopId int) (ForecastStop, error)
SearchByStop performs a search of the bus arrivals based on the stop id
type ForecastStop ¶ added in v0.4.0
type ForecastStop struct { Id int64 `json:"cp"` Name string `json:"np"` Latitude float64 `json:"py"` Longitude float64 `json:"px"` Lines []*ForecastLine `json:"l"` }
ForecastStop is a stop structure
type ForecastVehicle ¶ added in v0.4.0
type ForecastVehicle struct { Prefix int64 `json:"p"` Hour string `json:"t"` Accessible bool `json:"a"` UpdateTime string `json:"ta"` Latitude float64 `json:"py"` Longitude float64 `json:"px"` }
ForecastVehicle is a vehicle structure
type Line ¶ added in v0.2.0
type Line struct { Id int64 `json:"cl"` Circular bool `json:"lc"` DisplaySign string `json:"lt"` Type int64 `json:"tl"` Direction int64 `json:"sl"` MainTerminal string `json:"tp"` SecondaryTerminal string `json:"ts"` }
Line structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-linhas
type LineService ¶ added in v0.2.0
type LineService service
LineService provide functions to request lines endpoints
func (*LineService) Search ¶ added in v0.2.0
func (r *LineService) Search(filter string) ([]*Line, error)
Search performs a search of the bus lines based on the parameter informed (description or line number)
func (*LineService) SearchByDirection ¶ added in v0.2.0
func (r *LineService) SearchByDirection(filter string, direction int) ([]*Line, error)
SearchByDirection performs a search of the bus lines based on the parameter informed (description or direction)
type Stop ¶ added in v0.2.0
type Stop struct { Id int64 `json:"cp"` Name string `json:"np"` Address string `json:"ed"` Latitude float64 `json:"py"` Longitude float64 `json:"px"` }
Stop structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-paradas
type StopService ¶ added in v0.2.0
type StopService service
StopService provide functions to request stops endpoints
func (*StopService) Search ¶ added in v0.2.0
func (r *StopService) Search(filter string) ([]*Stop, error)
Search performs a search of the bus stops based on the parameter informed (stop name or address)
func (*StopService) SearchByCorridor ¶ added in v0.2.0
func (r *StopService) SearchByCorridor(corridorId int) ([]*Stop, error)
SearchByCorridor performs a search of the bus stops based on the corridor id
func (*StopService) SearchByLine ¶ added in v0.2.0
func (r *StopService) SearchByLine(lineId int) ([]*Stop, error)
SearchByLine performs a search of the bus stops based on the line id
type VehiclePosition ¶ added in v0.3.0
type VehiclePosition struct { Prefix int64 `json:"p"` Accessible bool `json:"a"` Hour string `json:"ta"` Latitude float64 `json:"py"` Longitude float64 `json:"px"` }
VehiclePosition relation of localized vehicles
type VehiclePositionLine ¶ added in v0.3.0
type VehiclePositionLine struct { FullSign string `json:"c"` Id int64 `json:"cl"` Direction int64 `json:"sl"` DestinationSign string `json:"lt0"` OriginSign string `json:"lt1"` QuantityVehicles int64 `json:"qv"` Vehicles []*VehiclePosition `json:"vs"` }
VehiclePositionLine relation of localized lines
type VehiclePositionLineResponse ¶ added in v0.3.0
type VehiclePositionLineResponse struct { Hour string `json:"hr"` Vehicles []*VehiclePosition `json:"vs"` }
VehiclePositionLineResponse structure
type VehiclePositionResponse ¶ added in v0.3.0
type VehiclePositionResponse struct { Hour string `json:"hr"` Lines []*VehiclePositionLine `json:"l"` }
VehiclePositionResponse structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-posicao
type VehiclePositionService ¶ added in v0.3.0
type VehiclePositionService service
VehiclePositionService provide functions to request vehicles position endpoints
func (*VehiclePositionService) All ¶ added in v0.3.0
func (r *VehiclePositionService) All() ([]*VehiclePositionLine, error)
All returns all vehicles position
func (*VehiclePositionService) SearchByCompany ¶ added in v0.3.0
func (r *VehiclePositionService) SearchByCompany(companyId int) ([]*VehiclePositionLine, error)
SearchByCompany search vehicles position by company id
func (*VehiclePositionService) SearchByLine ¶ added in v0.3.0
func (r *VehiclePositionService) SearchByLine(lineId int) ([]*VehiclePosition, error)
SearchByLine search vehicles position by line id