Skip to content

dev.katsute.onemta 1.0.0-RC-2

Install 1/2: Add this to pom.xml:
Learn more about Maven or Gradle
<dependency>
  <groupId>dev.katsute</groupId>
  <artifactId>onemta</artifactId>
  <version>1.0.0-RC-2</version>
</dependency>
Install 2/2: Run via command line
$ mvn install

About this package

You do not have to authenticate with GitHub to use this package, binaries are available on Maven Central https://mvnrepository.com/artifact/dev.katsute/onemta

OneMTA

Java wrapper for the MTA Bus and Subway API

Java CI MTA CI Maven Central version license

Overview

⚠ The MTA API Terms and Conditions prohibits developers from giving users direct access to MTA servers.
Any realtime data that is retrieved in this library must be served to users on your own servers.

Installation

OneMTA requires at least Java 8. OneMTA also requires the protobuf-java library to be installed.

Compiled jars can be found on Maven Central and the releases tab.

Authentication

Request a bus token at https://bt.mta.info/wiki/Developers/Index.

Request a subway token at https://api.mta.info/#/signup.

OneMTA requires static data from the MTA for most route and stop information. Latest static data for the MTA is available at http://web.mta.info/developers/developer-data-terms.html#data.

Only include static data for the API endpoints you are using. For the bus API you must include all boroughs plus bus company.

DataResource staticBusBx = DataResource.create(
    DataResourceType.Bus_Bronx,
    new File("bronx_google_transit.zip")
);
DataResource staticBusBk = DataResource.create(
    DataResourceType.Bus_Brooklyn,
    new File("brooklyn_google_transit.zip")
);
DataResource staticBusMt = DataResource.create(
    DataResourceType.Bus_Manhattan,
    new File("manhattan_google_transit.zip")
);
DataResource staticBusQn = DataResource.create(
    DataResourceType.Bus_Queens,
    new File("queens_google_transit.zip")
);
DataResource staticBusSI = DataResource.create(
    DataResourceType.Bus_StatenIsland,
    new File("staten_island_google_transit.zip")
);
DataResource staticBusBC = DataResource.create(
    DataResourceType.Bus_Company,
    new File("bus_company_google_transit.zip")
);
DataResource staticSubway = DataResource.create(
    DataResourceType.Subway,
    new File("subway_google_transit.zip")
);
DataResource staticLIRR = DataResource.create(
    DataResourceType.LongIslandRailroad,
    new File("lirr_google_transit.zip")
);
DataResource staticMNR = DataResource.create(
    DataResourceType.MetroNorthRailroad,
    new File("mnr_google_transit.zip")
);

MTA mta = MTA.create(busToken, subwayToken, staticBusBx, staticBusBk, staticBusMt, staticBusQn, staticBusSI, staticBusBC, staticSubway, staticLIRR, staticMNR);

(back to top)

Features

🗺 Routes

Retrieve routes along with alerts and vehicles on the route.

Bus.Route M1    = mta.getBusRoute("M1", DataResourceType.Bus_Manhattan);
Subway.Route SI = mta.getSubwayRoute("SI");
LIRR.Route PW   = mta.getLIRRRoute(9);
MNR.Route HM    = mta.getMNRRoute(2);

🚏 Stops

Retrieve stops with alerts and vehicles en route.

Bus.Stop stop   = mta.getBusStop(400561);
Subway.Stop GCT = mta.getSubwayStop("631");
LIRR.Stop FLS   = mta.getLIRRStop("FLS");
MNR.Stop WLN    = mta.getMNRStop("1WN");

🚍 Vehicles

Retrieve live vehicle information from stops and routes.

Bus.Vehicle[] busses     = stop.getVehicles();
Subway.Vehicle[] subways = SI.getVehicles();
LIRR.Vehicle[] lirr      = PW.getVehicles();
MNR.Vehicle[] mnr        = WLN.getVehicles();

⚠ Alerts

Retrieve alerts for all stops and routes.

Bus.Alert[] busAlerts       = mta.getBusAlerts();
Subway.Alert[] subwayAlerts = SI.getAlerts();
LIRR.Alert[] lirrAlerts     = FLS.getAlerts();
MNR.Alert[] mnrAlerts       = mta.getMNRAlerts();

(back to top)

Contributing

GitHub Copilot

GitHub Copilot

GitHub Copilot is strictly prohibited on this repository.
Pulls using this will be rejected.

  • Found a bug? Post it in issues.
  • Have a suggestion or looking for inspiration? Check out our discussions.
  • Want to further expand our project or site? Fork this repository and submit a pull request.

Sample response data available on the reference branch.

Updating Protobuf Files

  • Download latest protobuf from OneBusAway/onebusaway-gtfs-realtime-api
  • Save proto files in /protobuf
  • Change options and imports as defined in the protobuf.sh comments
  • Run protobuf.sh
  • Change all classes to abstract package private and add SuppressWarnings("all")

Notice About Tests

  • Tests are most reliable around rush hour.
  • Tests may not work during overnight hours.
  • Tests may not work if the selected routes are out of service.
  • Tests may not work it the select stops are out of service.

Running Tests Locally

For local tests you can use Java 8+, however only methods in the Java 8 API may be used. The src/main/java9 folder should not be marked as a source root.

  • (Bus) Run tests locally by adding a text file named bus.txt that contains the bus token in the src/test/java/resources directory.
  • (Subway) Run tests locally by adding a text file named subway.txt that contains the subway in the src/test/java/resources directory.

Running Tests Remotely

Devs running remote tests may do so by running the MTA CI workflow manually in the actions tab of your fork. Note that this requires two secrets, a BUS_TOKEN which contains the bus token, and a SUBWAY_TOKEN which contains the subway token.

(back to top)


License

This library is released under the GNU General Public License (GPL) v2.0.

Disclaimer

  • @Katsute and @KatsuteDev are not affiliated with the MTA.

  • By using the MTA API you are subject to their Terms and Conditions.

    In developing your app, you will provide that the MTA data feed is available to others only from a non-MTA server. Accordingly, you will download and store the MTA data feed on a non-MTA server which users of your App will access in order to obtain data. MTA prohibits the development of an app that would make the data available to others directly from MTA's server(s).

(back to top)