Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/katsutedev/onemta
The MTA Bus and Subway APIs all in one Java library
https://github.com/katsutedev/onemta
bus bus-arrival bus-locations bus-route bus-schedule bus-stop bus-time bus-tracking java lib library lirr mta nyct onemta rest-api subway subway-time train-schedule transit
Last synced: 3 days ago
JSON representation
The MTA Bus and Subway APIs all in one Java library
- Host: GitHub
- URL: https://github.com/katsutedev/onemta
- Owner: KatsuteDev
- License: gpl-2.0
- Created: 2021-11-23T04:23:53.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-22T10:39:30.000Z (7 months ago)
- Last Synced: 2024-04-22T11:47:27.059Z (7 months ago)
- Topics: bus, bus-arrival, bus-locations, bus-route, bus-schedule, bus-stop, bus-time, bus-tracking, java, lib, library, lirr, mta, nyct, onemta, rest-api, subway, subway-time, train-schedule, transit
- Language: Java
- Homepage: https://katsute.dev/product/onemta
- Size: 43.3 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
OneMTA
Java wrapper for the MTA Bus and Subway API
Documentation
•
MTA Developer Resources
•
MTA Google Group
Maven Central
•
GitHub Packages
•
Releases
> ⚠️ The MTA API [Terms and Conditions](https://new.mta.info/developers/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.**OneMTA is a Java wrapper for the [MTA SIRI REST API](https://bustime.mta.info/wiki/Developers/SIRIIntro) and [MTA Realtime GTFS API](https://api.mta.info/).
## Installation
OneMTA requires at least Java 8.
OneMTA also requires the [protobuf-java](https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java) library to be installed. Make sure you are using the same version as specified in the [pom.xml](https://github.com/KatsuteDev/OneMTA/blob/main/pom.xml) file.
Compiled binaries can be installed from:
* [Maven Central](https://mvnrepository.com/artifact/dev.katsute/onemta)
* [GitHub Packages](https://github.com/KatsuteDev/OneMTA/packages/1221214)
* [Releases](https://github.com/KatsuteDev/OneMTA/releases)#### Authentication
1. Request a bus token at .
2. OneMTA requires static data from the MTA for most route and stop information.
Latest static data for the MTA is available at .Static data is only required for the endpoints you are using. All boroughs are required for buses, including bus company.
[![static datafeeds](https://raw.githubusercontent.com/KatsuteDev/OneMTA/main/assets/static-gtfs-data.png)](https://new.mta.info/developers)
3. Initialize OneMTA
```java
MTA mta = MTA.create(
busToken,
DataResource.create(DataResourceType.Bus_Bronx, new File("google_transit_bronx.zip")),
DataResource.create(DataResourceType.Bus_Brooklyn, new File("google_transit_brooklyn.zip")),
DataResource.create(DataResourceType.Bus_Manhattan, new File("google_transit_manhattan.zip")),
DataResource.create(DataResourceType.Bus_Queens, new File("google_transit_queens.zip")),
DataResource.create(DataResourceType.Bus_StatenIsland, new File("google_transit_staten_island.zip")),
DataResource.create(DataResourceType.Bus_Company, new File("google_transit_bus_company.zip")),
DataResource.create(DataResourceType.Subway, new File("google_transit_subway.zip")),
DataResource.create(DataResourceType.LongIslandRailroad, new File("google_transit_lirr.zip")),
DataResource.create(DataResourceType.MetroNorthRailroad, new File("google_transit_mnr.zip"))
);
```## Features
#### Routes
Retrieve routes along with alerts and vehicles on the route.
```java
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.
```java
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.
```java
Bus.Vehicle[] bus = stop.getVehicles();
Subway.Vehicle[] subway = SI.getVehicles();
LIRR.Vehicle[] lirr = PW.getVehicles();
MNR.Vehicle[] mnr = WLN.getVehicles();
```#### Alerts
Retrieve alerts for all stops and routes.
```java
Bus.Alert[] busAlerts = mta.getBusAlerts();
Subway.Alert[] subwayAlerts = SI.getAlerts();
LIRR.Alert[] lirrAlerts = FLS.getAlerts();
MNR.Alert[] mnrAlerts = mta.getMNRAlerts();
```## Contributing
Sample response data available on the [`reference`](https://github.com/KatsuteDev/OneMTA/tree/reference) branch.
#### Updating Protobuf Files
1. Run `install.sh`
or
Install [protobuf](https://github.com/protocolbuffers/protobuf/releases) and [gtfs realtime proto](https://github.com/OneBusAway/onebusaway-gtfs-realtime-api/tree/master/src/main/proto/com/google/transit/realtime) manually
2. Run `protobuf.sh`#### Notice About Tests
- Tests are most reliable around rush hour.
- Tests may not work during overnight hours.
- Route tests may not work if the selected routes are out of service.
- Stop tests may not work it the selected stops are out of service.
- Alert tests may not work if no alerts are active.#### 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.
- You must run `install.sh` to initialize test resources.
- (Bus) Run tests locally by adding a text file named `bus.txt` that contains the bus token in the `src/test/java/resources` directory.#### Running Tests using GitHub Actions
Developers running remote tests through GitHub Actions may do so by running the `MTA CI` workflow manually in the actions tab of your fork. Note that this requires a single secret, a `BUS_TOKEN` which contains the bus token.
##
This library is released under the [GNU General Public License (GPL) v2.0](https://github.com/KatsuteDev/OneMTA/blob/main/LICENSE).
* [@Katsute](https://github.com/Katsute) and [@KatsuteDev](https://github.com/KatsuteDev) are not affiliated with the MTA.
* By using the MTA API you are subject to their [Terms and Conditions](https://new.mta.info/developers/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).