Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens are no longer required for GTFS feeds #204

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"image": "maven:3-eclipse-temurin-21",
"postAttachCommand": "git submodule update --init; ./install.sh; mvn compile",
"postAttachCommand": "git submodule update --init; mvn compile",
"shutdownAction": "stopContainer",
"customizations": {
"vscode": {
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/mta_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ jobs:
- name: Load Client ID
run: echo ${{ secrets.BUS_TOKEN }} > src/test/java/resources/bus.txt

- name: Load OAuth Token
run: echo ${{ secrets.SUBWAY_TOKEN }} > src/test/java/resources/subway.txt

- name: Load Test Group
run: echo ${{ matrix.group }} > src/test/java/resources/TEST_GROUP

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

<br>

> ⚠️ The MTA API [Terms and Conditions](https://api.mta.info/#/DataFeedAgreement) prohibits developers from giving users direct access to MTA servers.
> ⚠️ 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/#/landing).
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

Expand All @@ -41,18 +41,19 @@ Compiled binaries can be installed from:
#### Authentication

1. Request a bus token at <https://bt.mta.info/wiki/Developers/Index>.
2. Request a subway token at <https://api.mta.info/#/signup>.
2. ~~Request a subway token at <https://api.mta.info/#/signup>.~~

API keys are no longer required to access GTFS feeds.
3. 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>.
Latest static data for the MTA is available at <https://new.mta.info/developers>.

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-datafeeds.png)](http://web.mta.info/developers/developer-data-terms.html#data)
[![static datafeeds](https://raw.githubusercontent.com/KatsuteDev/OneMTA/main/assets/static-gtfs-data.png)](https://new.mta.info/developers)
4. Initialize OneMTA
```java
MTA mta = MTA.create(
busToken,
subwayToken,
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")),
Expand Down Expand Up @@ -142,11 +143,10 @@ For local tests you can use Java 8+, however only methods in the Java 8 API may

- 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.
- (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 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 two secrets, a `BUS_TOKEN` which contains the bus token, and a `SUBWAY_TOKEN` which contains the subway token.
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.

<div align="right"><a href="#top"><code>▲</code></a></div>

Expand All @@ -155,6 +155,6 @@ Developers running remote tests through GitHub Actions may do so by running the
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://api.mta.info/#/DataFeedAgreement).
* 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).
Binary file added assets/static-gtfs-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.katsute</groupId>
<artifactId>onemta</artifactId>
<version>2.1.0</version>
<version>3.0.0</version>

<profiles>
<profile>
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/dev/katsute/onemta/MTA.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Authenticate using {@link #create(String, String, DataResource...)}
*
* @since 1.0.0
* @version 1.0.0
* @version 3.0.0
* @author Katsute
*/
@SuppressWarnings({"SpellCheckingInspection", "UnusedReturnValue"})
Expand All @@ -42,31 +42,29 @@ public abstract class MTA {
* Creates an MTA API interface. Note that bus alerts require a subway token.
*
* @param busToken bus token
* @param subwayToken subway token
* @param resources <b>(required)</b> static data resource, see {@link DataResource}
* @return MTA
*
* @see #create(String, String, int, DataResource...)
* @since 1.0.0
* @since 3.0.0
*/
public static MTA create(final String busToken, final String subwayToken, final DataResource... resources){
return create(busToken, subwayToken, -1, resources);
public static MTA create(final String busToken, final DataResource... resources){
return create(busToken, -1, resources);
}

/**
* Creates an MTA API interface. Note that bus alerts require a subway token.
*
* @param busToken bus token
* @param subwayToken subway token
* @param cacheSeconds how long to cache responses for
* @param resources <b>(required)</b> static data resource, see {@link DataResource}
* @return MTA
*
* @see #create(String, String, DataResource...)
* @since 1.0.0
* @since 3.0.0
*/
public static MTA create(final String busToken, final String subwayToken, final int cacheSeconds, final DataResource... resources){
return new MTAImpl(busToken, subwayToken, cacheSeconds, resources);
public static MTA create(final String busToken, final int cacheSeconds, final DataResource... resources){
return new MTAImpl(busToken, cacheSeconds, resources);
}

// bus methods
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/dev/katsute/onemta/MTAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@
final class MTAImpl extends MTA {

final transient String busToken;
final transient String subwayToken;

final MTAService service;

private final DataResource[] resources;

MTAImpl(final String busToken, final String subwayToken, final int cacheSeconds, final DataResource... resources){
this.service = new MTAService(busToken, subwayToken, cacheSeconds);
MTAImpl(final String busToken, final int cacheSeconds, final DataResource... resources){
this.service = new MTAService(busToken, cacheSeconds);

this.busToken = busToken;
this.subwayToken = subwayToken;
this.resources = resources == null ? new DataResource[0] : Arrays.copyOf(resources, resources.length);
}

Expand Down
34 changes: 16 additions & 18 deletions src/main/java/dev/katsute/onemta/MTAService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ final class MTAService {

private final RequestCache cache;

private final Map<String,String> busAuth, subwayAuth;
private final Map<String,String> busAuth;

MTAService(final String busToken, final String subwayToken, final int cacheSeconds){
MTAService(final String busToken, final int cacheSeconds){
this.cache = new RequestCache(cacheSeconds);

busAuth = Collections.singletonMap("key", busToken);
subwayAuth = Collections.singletonMap("x-api-key", subwayToken);
}

private static String encodeUTF8(final String string){
Expand Down Expand Up @@ -96,63 +94,63 @@ final FeedMessage getACE(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-ace",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getBDFM(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-bdfm",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getG(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-g",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getJZ(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-jz",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getNQRW(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-nqrw",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getL(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-l",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage get1234567(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getSI(){
return cache.getProtobuf(
baseURL + "nyct%2Fgtfs-si",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

Expand All @@ -168,7 +166,7 @@ final FeedMessage getLIRR(){
return cache.getProtobuf(
baseURL + "lirr%2Fgtfs-lirr",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

Expand All @@ -185,7 +183,7 @@ final FeedMessage getMNR(){
return cache.getProtobuf(
baseURL + "mnr%2Fgtfs-mnr",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

Expand All @@ -201,31 +199,31 @@ final FeedMessage getBus(){
return cache.getProtobuf(
baseURL + "camsys%2Fbus-alerts",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getSubway(){
return cache.getProtobuf(
baseURL + "camsys%2Fsubway-alerts",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getLIRR(){
return cache.getProtobuf(
baseURL + "camsys%2Flirr-alerts",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

final FeedMessage getMNR(){
return cache.getProtobuf(
baseURL + "camsys%2Fmnr-alerts",
Collections.emptyMap(),
subwayAuth
Collections.emptyMap()
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/dev/katsute/onemta/CompilerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ abstract class CompilerTests {
@SuppressWarnings("SpellCheckingInspection")
private void setup(){
String busToken = "";
String subwayToken = "";

// setup

MTA mta = MTA.create(
busToken,
subwayToken,
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")),
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/dev/katsute/onemta/TestProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ public static void acquireTestLock(){
//

private static final File bus = new File(test_resources, "bus.txt");
private static final File subway = new File(test_resources, "subway.txt");

private static final boolean hasBus = bus.exists();
private static final boolean hasSubway = subway.exists();

private static final List<DataResourceType> resources = Arrays.asList(
DataResourceType.Subway,
Expand All @@ -96,7 +94,7 @@ public static void acquireTestLock(){

public static MTA getOneMTA(){
try{
if(!hasBus && !hasSubway)
if(!hasBus)
assumeTrue(false, "No token defined, skipping tests");

acquireTestLock();
Expand All @@ -105,7 +103,7 @@ public static MTA getOneMTA(){
for(final DataResourceType type : TestProvider.resources)
resources.add(DataResource.create(type, new File(test_resources, "resource_" + type.name().toLowerCase() + ".zip")));

return mta = MTA.create(strip(readFile(bus)), strip(readFile(subway)), resources.toArray(new DataResource[0]));
return mta = MTA.create(strip(readFile(bus)), resources.toArray(new DataResource[0]));
}catch(final IOException e){
fail(e);
return null;
Expand Down
Loading