Skip to content

Commit

Permalink
Merge pull request #48 from raumobil/feat/agencies-query
Browse files Browse the repository at this point in the history
Add agencies query
  • Loading branch information
leonardehrenfried authored Jun 12, 2024
2 parents c985415 + d4fbe54 commit 32e3fa9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/opentripplanner/client/OtpApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.opentripplanner.client.model.Agency;
import org.opentripplanner.client.model.Pattern;
import org.opentripplanner.client.model.Route;
import org.opentripplanner.client.model.Stop;
Expand Down Expand Up @@ -109,6 +110,18 @@ public List<Pattern> patterns() throws IOException {
return deserializeList(json, type, "/data/patterns");
}

/**
* Return the list of agencies.
*
* @link <a href="https://docs.opentripplanner.org/api/dev-2.x/graphql-gtfs/queries/agencies">OTP
* API docs</a>
*/
public List<Agency> agencies() throws IOException {
var json = sendRequest(GraphQLQueries.agencies());
var type = listType(Agency.class);
return deserializeList(json, type, "/data/agencies");
}

/**
* Returns a Stop with limited information.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static String patterns() {
return loadQuery("patterns");
}

public static String agencies() {
return loadQuery("agencies");
}

public static String stop() {
return loadQuery("stop");
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/queries/agencies.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query {
agencies {
gtfsId
name
}
}
16 changes: 16 additions & 0 deletions src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ public void patterns() throws IOException {
});
}

@Test
public void agencies() throws IOException {

var result = client.agencies();

LOG.info("Received {} agencies", result.size());

assertFalse(result.isEmpty());

result.forEach(
agency -> {
assertNotNull(agency.name());
assertNotNull(agency.id());
});
}

@Test
public void stop() throws IOException {

Expand Down

0 comments on commit 32e3fa9

Please sign in to comment.