mta-gtfs-realtime-bindings
v0.0.5
Published
Javascript classes generated from the GTFS-realtime protocol buffer specification.
Downloads
4
Readme
JavaScript GTFS-realtime Language Bindings
Provides JavaScript classes generated from the GTFS-realtime Protocol Buffer specification. These classes will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into JavaScript objects.
These bindings are designed to be used in the Node.js environment, but with some effort, they can probably be used in other JavaScript environments as well.
We use the ProtBuf.js library for JavaScript Protocol Buffer support.
Add the Dependency
To use the mta-gtfs-realtime-bindings
classes in your own project, you need to
first install our Node.js npm package:
npm install mta-gtfs-realtime-bindings
Example Code
The following Node.js code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.
const GtfsRealtimeBindings = require('mta-gtfs-realtime-bindings');
const rp = require('request-promise');
rp({
method: 'GET',
url: 'http://datamine.mta.info/mta_esi.php?key=MTA_API_KEY',
encoding: null,
}).then((buf) => {
const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buf);
feed.entity.forEach((entity) => {
if (entity.trip_update) {
console.log(entity.trip_update);
}
});
}).catch(e => console.log(e));
For more details on the naming conventions for the Javascript classes generated from the gtfs-realtime.proto, check out the ProtoBuf.js project which we use to handle our Protocol Buffer serialization.