Name: onebusaway-client-library
Owner: OneBusAway
Description: A Java library that makes it easy to call the OneBusAway REST APIs
Created: 2015-09-19 00:03:17.0
Updated: 2018-04-17 21:47:19.0
Pushed: 2017-03-30 01:53:47.0
Size: 264
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Java library that makes it easy to call the OneBusAway REST APIs
You'll need JDK 7 or higher.
You can use Maven to add this library to your project. Add the following to your pom.xml
:
ositories>
<repository>
<id>public.onebusaway.org</id>
<url>http://nexus.onebusaway.org/content/groups/public/</url>
</repository>
positories>
endencies>
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-client-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
pendencies>
The below example shows how to get the stops near a location, first by using the results of the OBA Regions API, and then secondly by setting a custom OBA Server API.
ate static void callObaApis() throws IOException {
Set the API key to be used - should be changed to your API key
aApi.getDefaultContext().setApiKey("TEST");
aRegionsResponse response = null;
Call the OBA Regions API (http://regions.onebusaway.org/regions-v3.json)
sponse = ObaRegionsRequest.newRequest().call();
rayList<ObaRegion> regions = new ArrayList<ObaRegion>(Arrays.asList(response.getRegions()));
r (ObaRegion r : regions) {
if (r.getName().equalsIgnoreCase("Tampa")) {
ObaApi.getDefaultContext().setRegion(r);
// Get the stops for the region named "Tampa"
getStops();
}
*
An example of setting a custom API server
/
First, clear the region, if it was already set
aApi.getDefaultContext().setRegion(null);
An example of setting a custom API server
ring url = "http://api.tampa.onebusaway.org/api/";
aApi.getDefaultContext().setBaseUrl(url);
tStops();
ate static void getStops() throws IOException {
Location l = new Location("Test");
l.setLatitude(28.0664191);
l.setLongitude(-82.4298721);
ObaStopsForLocationResponse response2 = null;
// Call the OBA stops-for-location API (http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/stops-for-location.html)
response2 = new ObaStopsForLocationRequest.Builder(l)
.setQuery("3105")
.build()
.call();
nal ObaStop[] list = response2.getStops();
r (ObaStop s : list) {
System.out.println(s.getName() + "\n");