This package has been deprecated

Author message:

I wrote this module a very long time ago; you should use something else.

bart-api

0.0.0 • Public • Published

bart-api

THIS IS A SYSTEM-WIDE BART ADVISORY. ALL ELEVATORS ARE WORKING. THAT IS ALL.

Install:

npm install bart-api

Start it up:

var Bart = require('bart-api');
 
// You can get yourself one of these at http://api.bart.gov/api/register.aspx
var key = require('./config.json').key;
 
var bart = new Bart(key);

Make an API request, receive xml

  // Get arrival schedule information
  bart.sched.arrive({
    orig: 'SFIA',
    dest: 'PITT'
  }, function (err, xml, body) {
    if (err) {
      throw err;
    }
 
    // xml is a parser instance from https://github.com/polotek/libxmljs
    // it supports xpath and more!
    var trips = [];
 
    xml.find('/root/schedule/request/trip').forEach(function (trip) {
      trips.push({
        orig: trip.attr('origin').value(),
        dest: trip.attr('destination').value(),
        times: {
          orig: trip.attr('origTimeMin').value(),
          dest: trip.attr('destTimeMin').value()
        },
        legs: trip.find('leg').map(function (leg) {
          return {
            orig: leg.attr('origin').value(),
            dest: leg.attr('destination').value(),
            line: leg.attr('line').value(),
            head: leg.attr('trainHeadStation').value(),
            times: {
              orig: leg.attr('origTimeMin').value(),
              dest: leg.attr('destTimeMin').value()
            }
          };
        })
      })
    });
 
    // If you hate libxmljs, you can access the raw buffered body too!
    //
    //     console.log(body);
    //
    // bart.sched.arrive() will also return the request instance, if you
    // would rather parse the output using a streaming parser such as
    // sax-js.
  });

More Reading:

License:

MIT/X11.

Package Sidebar

Install

npm i bart-api

Weekly Downloads

1

Version

0.0.0

License

MIT/X11

Last publish

Collaborators

  • jesusabdullah