sptrans

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sptrans is a Go client library for the SPTrans Olho Vivo API.

Authentication:

	token = "123456"
	client = sptrans.NewClient(token)
        client.Authenticate()

Search Route by description or number:

client.Route.Search("Lapa")
client.Route.Search("8000")

Search Route by direction:

client.Route.SearchByDirection("Lapa", 1)
client.Route.SearchByDirection("Lapa", 2)

Index

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
	Route   *RouteService
	Token   string
}

Client is a SPTrans client for making Olho Vivo API requests

func NewClient

func NewClient(token string) *Client

NewClient returns client with default configurations

func (*Client) Authenticate

func (c *Client) Authenticate() (bool, error)

Authenticate authenticates according to client token

func (*Client) Request

func (c *Client) Request(method, path string, bodyParams interface{}, decoder interface{}) (*http.Response, error)

Request enables requests for a given api path, and decodes the return according to a structure

type Route

type Route struct {
	Cl int64  `json:"cl"`
	Lc bool   `json:"lc"`
	Lt string `json:"lt"`
	Sl int64  `json:"sl"`
	Tl int64  `json:"tl"`
	Tp string `json:"tp"`
	Ts string `json:"ts"`
}

Route structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-linhas

type RouteService

type RouteService service

RouteService provide functions to request routes endpoints

func (*RouteService) Search

func (r *RouteService) Search(filter string) ([]*Route, error)

Search performs a search of the bus lines based on the parameter informed (description or line number)

func (*RouteService) SearchByDirection

func (r *RouteService) SearchByDirection(filter string, direction int) ([]*Route, error)

SearchByDirection performs a search of the bus lines based on the parameter informed (description or direction)

Jump to

Keyboard shortcuts

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