0.0.4 • Published 9 years ago

cta-api v0.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

cta-api-node

Thin node wrapper for the Chicago Transit Authority API written in Node.js

Notes

I am new to node. My concentration was making this an extremely thin wrapper using only node core modules. As such, you will find no non-core dependencies. I also felt that testing would be over kill.

Responses are in XML. Take this up with Rahm.

Lots of juicy info for Chicago's developers here:

http://www.transitchicago.com/developers/

Complete list of 'L' Stops:

https://data.cityofchicago.org/Transportation/CTA-System-Information-List-of-L-Stops/8pix-ypme

Usage

Get the api keys from Chicago Trainsit above

$ export CTA_TRAIN_API_KEY=hunter2
$ export CTA_BUS_API_KEY=azureDiamond
$ node my_awesome.js
// my_awesome.js

var ctaNode = require("cta-api");

var trainApiKey = process.env.CTA_TRAIN_API_KEY
    , busApiKey = process.env.CTA_BUS_API_KEY;

ctaNode
  .train
  .arrivals
  .get({ mapid: 40360, max: 1, key: trainApiKey }, 
      function(data) { console.log("Data: " + data); },
      function(e) { console.log("Error: " + e.message); });

Trains

Official Train Tracker API:
http://www.transitchicago.com/developers/ttdocs/default.aspx

Locations

Parameters

NameValueDescription
mapidNumeric station identifier (required if stpid not specified)A single five-digit code to tell the server which station you’d like to receive predictions for. See appendix for information about valid station codes.
stpidNumeric stop identifier (required if mapid not specified)A single five-digit code to tell the server which specific stop (in this context, specific platform or platform side within a larger station) you’d like to receive predictions for. See appendix for information about valid stop codes.
maxMaximum results (optional)The maximum number you’d like to receive (if not specified, all available results for the requested stop or station will be returned)
rtRoute code (optional)Allows you to specify a single route for which you’d like results (if not specified, all available results for the requested stop or station will be returned)
keyAlphanumeric API key (required)Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.
var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.arrivals.get({ mapid: 40360, max: 1, key: trainApiKey }, callback, errorCb)

Follow That Train

Parameters

NameValueDescription
runnumberTrain Run Number (required)Allows you to specify a single run number for a train for which you’d like a series of upcoming arrival estimations.
keyAlphanumeric API key (required)Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.
var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.followThisTrain.get({ runnumber: 909, key: trainApiKey }, callback, errorCb)

Locations

Parameters

NameValueDescription
rtTrain route(s) (required)Allows you to specify one or more routes for which you’d like train location information.
keyAlphanumeric API key (required)Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.
var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.locations.get({ rt: 'red', key: trainApiKey }, callback, errorCb)

Buses

Official Bus Tracker API:
http://www.transitchicago.com/assets/1/developer_center/BusTime_Developer_API_Guide.pdf

Time

NameValueDescription
Keystring (required)25-digit Bus Tracker API access key.
  ctaNode.bus.time.get({ key: busApiKey }, callback, errorCb);

Vehicles

NameValueDescription
Keystring (required)25-digit Bus Tracker API access key.
Vidcomma-delimited list of vehicle IDs (not available with rt parameter)Set of one or more vehicle IDs whose location should be returned. For example: 509,392,201,4367 will return information for four vehicles (if available). A maximum of 10 identifiers can be specified.
Rtcomma-delimited list of route designators (not available with vid parameter)Set of one or more route designators for which matching vehicles should be returned. For example: X3,4,20 will return information for all vehicles currently running those three routes (if available). A maximum of 10 identifiers can be specified.
  ctaNode.bus.vehicles.get({ key: busApiKey, vid: [509,392] }, callback, errorCb);
  ctaNode.bus.vehicles.get({ key: busApiKey, rt: [80] }, callback, errorCb);

Routes

NameValueDescription
Keystring (required)25-digit Bus Tracker API access key.
  ctaNode.bus.routes.get({ key: busApiKey }, callback, errorCb);

Route Directions

NameValueDescription
Keystring (required)25-digit Bus Tracker API access key.
RtSingle route designator (required)Alphanumeric designator of a route (ex. “20” or “X20”) for which a list of available directions is to be returned.
  ctaNode.bus.routes.get({ key: busApiKey }, callback, errorCb);
NameValueDescription
keystring (required)25-digit Bus Tracker API access key.
rtSingle route designator (required)Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned.
  ctaNode.bus.directions.get({ key: busApiKey, rt: 80 }, callback, errorCb);

Stops

NameValueDescription
keystring (required)25-digit Bus Tracker API access key.
rtSingle route designator (required)Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned.
dirSingle route direction (required)Direction of the route (ex. “East Bound”) for which a list of available stops is to be returned.
  ctaNode.bus.stops.get({ key: busApiKey, rt: 80, dir: "Westbound" }, callback, errorCb);

Patterns

NameValueDescription
keystring (required)25-digit Bus Tracker API access key.
pidcomma-delimited list of pattern IDs (not available with rt parameter)Set of one or more pattern IDs whose points should be returned. For example: 56,436,1221 will return points from three (3) patterns. A maximum of 10 identifiers can be specified.
rtSingle route designator (required)Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned.
  ctaNode.bus.patterns.get({ key: busApiKey, rt: 80, vid: 909, top: 5 }, callback, errorCb);

Predictions

NameValueDescription
keystring (required)25-digit Bus Tracker API access key.
stpidcomma-delimited list of stop IDs (not available with vid parameter)Set of one or more stop IDs whose predictions are to be returned. For example: 5029,1392,2019,4367 will return predictions for the four stops. A maximum of 10 identifiers can be specified.
rtcomma-delimited list of route designators (optional, available with stpid parameter)Set of one or more route designators for which matching predictions are to be returned.
vidcomma-delimited list of vehicle IDs (not available with stpid parameter)Set of one or more vehicle IDs whose predictions should be returned. For example: 509,392,201,4367 will return predictions for four vehicles. A maximum of 10 identifiers can be specified.
topnumber (optional)Maximum number of predictions to be returned.
  ctaNode.bus.predictions.get({ key: busApiKey, rt: 20, stpid: 456 }, callback, errorCb);

Service Bulletins

NameValueDescription
keystring (required)25-digit Bus Tracker API access key.
rtcomma-delimited list of route designators (optional, available with stpid parameter)Set of one or more route designators for which matching predictions are to be returned.
rtdirSingle route direction (optional)Direction of travel of the route specified in the rt parameter. The rt parameter is required when using the rtdir parameter.
stpidcomma-delimited list of stop IDs (not available with vid parameter)Set of one or more stop IDs whose predictions are to be returned. For example: 5029,1392,2019,4367 will return predictions for the four stops. A maximum of 10 identifiers can be specified.
  ctaNode.bus.bulletins.get({ key: busApiKey, rt: 20, stpid: 456 }, callback, errorCb);

Alerts

Gives you information on stop/station outages and signifant alerts.

No options.
There appears to be HTML in some of the alerts. Take it up with Rahm.

var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.customerAlerts.routeStatus.get({}, callback, errorCb);
ctaNode.customerAlerts.detailedAlerts.get({}, callback, errorCb);

Contribute

Fork, code, pull request

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago