Java client library to retrieve data from The Blue Alliance using TBA API v3
Full Javadoc documentation can be found here
Begin by creating a TBA object with your Read TBA API Key. This can be found or generated on your account dashboard.
String authKey = // your TBA API read key
TBA tba = new TBA(authKey);
The library allows access to almost all of the calls in The Blue Alliance API v3 documentation.
They are grouped into requests with team, event, district, or match parameters, and you will need to use the teamRequest
, eventRequest
, or matchRequest
instance variables found in the TBA
class.
Here is an example of retrieving an array of teams in the FIRST Mid-Atlantic district in 2017:
Team[] midAtlanticTeams = tba.districtRequest.getTeams("2017mar");
A list of request methods for each request object can be found here.
If you want to utilize the If-Modified-Since
and Last-Modified
headers, you will need to make a direct URL request with the getDataTBA(String urlDirectory, String ifModifiedSince)
method in the DataRequest
class. This will return an APIResponse
object with JSON data, the HTTP response code, and the Last-Modified
header.
The JSON data will need to be deserialized into an object model with a method in the Deserializer
class before being used.
Here is an example of fetching the Match
objects for the 2017 Mount Olive District Event, if they have been updated.
APIResponse resp = tba.dataRequest.getDataTBA("/event/2017njfla/matches");
String lastModified = resp.getLastModified();
Match[] matchList = Deserializer.toMatchArray(resp.getJson());
// Execute the following code block after waiting or in a separate method
resp = tba.dataRequest.getDataTBA("/event/2017njfla/matches", lastModified);
if(resp.getResponseCode()!=304){ // HTTP code 304 indicates no change
teamList = Deserializer.jsonToTeamArray(resp.getJson());
lastModified = resp.getLastModified();
}
}
A list of object model classes and their getter methods for instance variables can be found here. Please note that the master
branch of this repository contains updated object models for the current season's code, and object models for past seasons can be found in other branches.
You will need Gson to use the released compiled TBA API JAR file in your project. Gson can be installed with Maven, via a JAR file, or with Gradle if you include the following in your build.gradle
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}
Note that you will need Gradle to compile this repository's source code if you do not get Gson.
Feel free to contact Spencer Ng at sng1488 (at) gmail (dot) com or create a pull request if you have any questions, fixes, or suggestions.