bart-api

Api client for api.bart.gov

npm install bart-api
1 downloads in the last day
3 downloads in the last week
5 downloads in the last month

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.

npm loves you