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

node-emtmad-bus-promise

v2.2.0

Published

Nodejs library to access services from the public API of the Public Transport Authority of Madrid, Spain (EMT) with a Promises twist

Downloads

9

Readme

node-emtmad-bus-promise

NPM version Build Status codecov Dependency Status Dev Dependency Status

Node.js module to access services from the public API of the Public Transport Authority of Madrid, Spain (EMT).

This module is a fork of https://github.com/alvaroreig/emtmad-bus-times-node that returns Promise objects instead of doing sync calls to the EMT API.

API Access

Request access to the API at http://opendata.emtmadrid.es/Formulario. You will be given a Client ID and a Passkey.

Installation

node-emtmad-bus-promise is packaged using NPM. Just require the package inside your code:

var EMTAPI = require('node-emtmad-bus-promise');

Initializing the API

In order to use this API you need to set two environment variables with your Client ID and Passkey. These variables need to be set before using require on the module.

EMT_APP_ID = <your client id>
EMT_PASSKEY = <your passkey>

Usage: get incoming buses to a given bus stop

Call the function getIncomingBusesToStop(busStopNumber) and a Promise will be returned that fulfills to an array of estimations:

    let stop = {
        Id: 3041
    }

    EMTAPI.getIncomingBusesToStop(stop.Id)
        .then(function (arriving) {
            stop.arriving = arriving;
            resolve(stop);
        })
        .catch(function (error) {
            resolve(`Error: ${error}`);
        });

The array of estimations is built with Bus objects that represent an incoming bus to the specified bus stop. The most relevant attributes for each bus are:

{
    "lineId": "32", // The line of the bus
    "busDistance": 9, // In meters
    "busTimeLeft": 0 // In seconds
}

Usage: get stops close to a location

Call the function getStopsFromLocation(location, radius) and a Promise will be returned that fulfills to an array of stops:

    let location = {
        latitude: -3.7324823992585,
        longitude: 40.377653538528
    }
    let searchRadius = 250;

    EMTAPI.getStopsFromLocation(location, searchRadius)
        .then(function (stops) {
            // do something
        })
        .catch(function (error) {
            resolve(`Error: ${error}`);
        });

The array of stops is built with Stop objects that look like this:

{
    stopId: '2443',
    name: 'AV.ABRANTES-PZA.LASMENINAS',
    postalAddress: 'Av.deAbrantes, 106',
    longitude: -3.7324823992585,
    latitude: 40.377653538528,
    line: [Line Object]
}

Usage: get stops of a line

Call the function getStopsLine(line, direction) and a Promise will be returned that fulfills to the whole of object returned by the EMT API. Since this query is pretty time consuming, the results are cached per line/direction combination to speed up things.

    let line = "118"; // line should be the lineId and not the label of the line
    let direction = 1; // lines have two directions represented either by: 1 or 2

    EMTAPI.getStopsLine(line, direction)
        .then(function (results) {
            // do something
        })
        .catch(function (error) {
            resolve(`Error: ${error}`);
        });

The object is described in the EMT API and looks like this:

{
    lineId: 516, // Line Id
    label: 'N16', // Label for this line
    destination: 'TEXT', // Destination of line
    incidents: 0 // 0: No incidents, 1: Incidents
    stop: [] // List of Stop
    line: [] // List of Line
}

Further reading

The objects returned in this API are exactly the same as the EMT API. A comprehensive documentation of the objects returned by the EMT API can be downloaded in the following link: http://opendata.emtmadrid.es/Documentos/Opendata-v-1-12.aspx

Development

Do you want to contribute? Great! Pull requests are more than welcome.