olhovivo

1.1.0 • Public • Published

node-olhovivo

Build Status Coverage Status Dependency Status devDependency Status npm downloads npm version


A node.js wrapper for the SPTrans Olho Vivo API.

Installing

You can install this library with:

npm install --save olhovivo

Usage

var OlhoVivoApi = require('olhovivo');
var olhovivoApi = new OlhoVivoApi({
  token: process.env.SPTRANS_TOKEN,
});
 
olhovivoApi.queryLines('bandeira')
  .then(function(lines) {
    console.log(lines);
  });

Progress

Wrapped endpoints:

  • POST /Login/Autenticar?token={token}
  • GET /Linha/Buscar?termosBusca={termosBusca}
  • GET /Linha/CarregarDetalhes?codigoLinha={codigoLinha}
  • GET /Parada/Buscar?termosBusca={termosBusca}
  • GET /Parada/BuscarParadasPorLinha?codigoLinha={codigoLinha}
  • GET /Parada/BuscarParadasPorCorredor?codigoCorredor={codigoCorredor}
  • GET /Corredor
  • GET /Posicao?codigoLinha={codigoLinha}
  • GET /Previsao?codigoParada={codigoParada}&codigoLinha={codigoLinha}
  • GET /Previsao/Linha?codigoLinha={codigoLinha}
  • GET /Previsao/Parada?codigoParada={codigoParada}

Documentation

OlhoVivoApi

OlhoVivoApi is a class wrapping the Olho Vivo real-time API. The token option is not required if the deferAuthentication option is set to true.

Params:

  • Object options
  • String [options.token] OlhoVivo API token (see http://bit.ly/1zjTGHj)
  • String [options.baseUrl='http://api.olhovivo.sptrans.com.br/v']
  • Boolean [options.deferAuthentication=false] By default, the constructor will immediatelly try to authenticate with the API and store the result of this operation in a promise to the authenticated cookie jar. If this option is set to true, the wrapper will only authenticate itself when OlhoVivoApi.prototype.authenticate([token]) is called manually.
  • Mixed [options.version='0']

OlhoVivoApi.prototype.queryLines(query)

Queries the API for lines matching some search string.

Wraps the request: GET /Linha/Buscar?termosBusca={query}

Params:

  • String query

Return:

  • Promise. results Returns a promise to the lines matching the query

OlhoVivoApi.prototype.lineDetails(lineCode)

Fetches details for a given line code

Wraps the request: GET /Linha/CarregarDetalhes?codigoLinha={codigoLinha}

Params:

  • Mixed lineCode

Return:

  • Promise. results Returns a promise to the line's "details"

OlhoVivoApi.prototype.queryStops(query)

Queries for stops. If the query is a string, it'll work the same as queryLines, two extra options are provided, however. Querying by line code or express lane code. This is done by passing an object rather than a string, with either a lineCode or expressLaneCode field (not both).

Wraps the requests:

  • GET /Parada/Buscar?termosBusca={termosBusca}
  • GET /Parada/BuscarParadasPorLinha?codigoLinha={codigoLinha}
  • GET /Parada/BuscarParadasPorCorredor?codigoCorredor={codigoCorredor}

Example:

var olhovivoapi = new OlhoVivoApi(process.env.SPTRANS_TOKEN);
 
olhovivoapi.queryStops('bla');                     // Stops matching 'bla'
olhovivoapi.queryStops({ lineCode: 33674 });       // Stops in this line
olhovivoapi.queryStops({ expressLaneCode: 0000 }); // Stops in this lane

Params:

  • [object Object] query If a string is provided, the stops

Return:

  • Promise. results Returns a promise to the stops matching the query

OlhoVivoApi.prototype.expressLanes()

Fetches a list of all existent express lane objects

Wraps the request: GET /Corredor

Return:

  • Promise.

OlhoVivoApi.prototype.linePositions(lineCode)

Queries the API for a line buses' positions.

Wraps the request: GET /Posicao?codigoLinha={codigoLinha}

Params:

  • Mixed lineCode

Return:

  • Promise. A promise to this line buses' positions

OlhoVivoApi.prototype.arrivalTimes(query)

Gets the arrival times for a certain stop and/or buses in a specific line. If both a lineCode and stopCode are provided, the result will be the arrival times for buses on the target line until the target stop. If only a stopCode is provided, the result will be the arrival times for all buses on the target stop. And if only a lineCode is provided, the result will be the arrival times for all buses on the target line on all stops.

Wraps the requests:

  • GET /Previsao?codigoParada={codigoParada}&codigoLinha={codigoLinha}
  • GET /Previsao/Linha?codigoLinha={codigoLinha}
  • GET /Previsao/Parada?codigoParada={codigoParada}

Params:

  • Object query If a string is provided, the stops
  • Object [query.lineCode]
  • Object [query.stopCode]

Return:

  • Promise. results Returns a promise to matching buses' arrival times

`OlhoVivoApi.prototype.authenticate(token)``

Authenticates the wrapper. Called automatically on the constructor by default.

Wraps the request: POST /Login/Autenticar?token={token}

Params:

  • String [token] Defaults to the options value. If provided will overwrite the cached ._options.token value.

Return:

  • Promise. Returns a promise to the instance itself after authentication

License

This code is licensed under the MIT license for Pedro Tacla Yamada. For more information please refer to the LICENSE file.

Donations

Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y

Package Sidebar

Install

npm i olhovivo

Weekly Downloads

11

Version

1.1.0

License

MIT

Last publish

Collaborators

  • yamadapc