npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

olhovivo

v1.1.0

Published

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

Downloads

4

Readme

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:

  • [x] POST /Login/Autenticar?token={token}
  • [x] GET /Linha/Buscar?termosBusca={termosBusca}
  • [x] GET /Linha/CarregarDetalhes?codigoLinha={codigoLinha}
  • [x] GET /Parada/Buscar?termosBusca={termosBusca}
  • [x] GET /Parada/BuscarParadasPorLinha?codigoLinha={codigoLinha}
  • [x] GET /Parada/BuscarParadasPorCorredor?codigoCorredor={codigoCorredor}
  • [x] GET /Corredor
  • [x] GET /Posicao?codigoLinha={codigoLinha}
  • [x] GET /Previsao?codigoParada={codigoParada}&codigoLinha={codigoLinha}
  • [x] GET /Previsao/Linha?codigoLinha={codigoLinha}
  • [x] 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