1.1.0 • Published 8 years ago

olhovivo v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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:

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:

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:

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

1.1.0

8 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago