Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Commit d09cdf2

Browse files
committed
Functionally finished; begin working on documentation
1 parent 2248580 commit d09cdf2

29 files changed

Lines changed: 1085 additions & 87 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ local.properties
5959
.classpath
6060

6161
# End of https://www.gitignore.io/api/eclipse
62+
/.gradle/

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
# TBA-API-Java-Library
22

3-
Java library for The Blue Alliance API v3
3+
Java client library to retrieve data from The Blue Alliance using TBA API v3
44

5-
Work in progress
5+
The library is essentially complete, but documentation is in progress.
6+
7+
## Usage
8+
9+
Begin by creating a TBA object with your Read TBA API Key. This can be found or generated on your [account dashboard](https://www.thebluealliance.com/account).
10+
11+
String authKey = // your TBA API read key
12+
TBA tba = new TBA(authKey);
13+
14+
### Regular Usage
15+
16+
The library allows access to almost all of the calls in [The Blue Alliance API v3 documentation](https://www.thebluealliance.com/apidocs/v3). They are grouped into requests with team, event, district, or match parameters:
17+
18+
**`tba.teamRequest`**
19+
20+
* `getTeam(teamNumber)`: Gets a `Team` object for the team referenced by the given number (an `int`).
21+
* `getSimpleTeam(teamNumber): Gets a `SimpleTeam` object for the team referenced by the given number.
22+
* `getYearsParticipated(teamNumber): Gets a list of years in which the team participated in at least one competition.
23+
* getDistricts(teamNumber): Gets a list of `District` objects for each year the team was in a district. Will return `null` if the team was never in a district.
24+
* to be continued
25+
26+
**`tba.eventRequest`**
27+
28+
* to be continued
29+
30+
**`tba.districtRequest`**
31+
32+
* to be continued
33+
34+
**`tba.matchRequest`**
35+
36+
* to be continued
37+
38+
### Advance Usage
39+
40+
If you want to utilize the `If-Modified-Since` and `Last-Modified` headers, you will need to make a direct URL request (following the documentation). This will return an `APIResponse` object with JSON data, the HTTP response code, and the `Last-Modified` header.
41+
42+
The JSON data will need to be deserialized into an object model with a method in the `Deserializer` class before being used.
43+
44+
Here is an (extremely inefficient) example of continuously fetching the `Team` objects for an event (`2017njfla`), if they have been updated.
45+
46+
TBA tba = new TBA(authKey);
47+
APIResponse resp = tba.dataRequest.getDataTBA("/event/2017njfla/teams");
48+
String lastModified = resp.getLastModified();
49+
Team[] teamList = Deserializer.toTeamArray(resp.getJson());
50+
while(true){
51+
resp = tba.dataRequest.getDataTBA("/event/2017njfla/teams", lastModified);
52+
if(resp.getResponseCode()!=304){
53+
teamList = Deserializer.jsonToTeamArray(resp.getJson());
54+
lastModified = resp.getLastModified();
55+
}
56+
}
57+
58+
## Models
59+
60+
Most of the object models follow those on The Blue Alliance API documentation, with appropriately named getter methods:
61+
62+
**Award**
63+
64+
* `String getName()`: The name of the award as provided by FIRST. May vary for the same award type.
65+
* `int getAwardType()`: Type of award given. See [here](https://github.com/the-blue-alliance/the-blue-alliance/blob/master/consts/award_type.py#L6) for details.
66+
* `String getEventKey()`: The `event_key` of the event the award was won at.
67+
* `AwardRecipient[] getRecipientList()`: A list of recipients of the award at the event. Either team_key and/or awardee for individual awards.
68+
* `int getYear()`: The year this award was won.
69+
70+
## Contact
71+
72+
Feel free to contact me at sng1488@gmail.com or create a pull request if you have any questions, fixes, or suggestions. This library is (currently) unaffiliated with [FRC Team 25](http://raiderrobotix.org).

src/main/java/com/thebluealliance/Deserializer.java

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,114 @@ public class Deserializer {
77

88
final static Gson gson = new Gson();
99

10-
public static Team jsonToTeam(String jsonData){
10+
public static Team toTeam(String jsonData){
1111
Team team = gson.fromJson(jsonData, Team.class);
1212
return team;
1313
}
1414

15-
public static SimpleTeam jsonToSimpleTeam(String jsonData){
15+
public static Team[] toTeamArray(String jsonData){
16+
Team[] teamArray = gson.fromJson(jsonData, Team[].class);
17+
return teamArray;
18+
}
19+
20+
public static SimpleTeam toSimpleTeam(String jsonData){
1621
SimpleTeam team = gson.fromJson(jsonData, SimpleTeam.class);
1722
return team;
1823
}
1924

20-
public static int[] jsonToIntArray(String jsonData){
25+
public static SimpleTeam[] toSimpleTeamArray(String jsonData){
26+
SimpleTeam[] simpleTeamArray = gson.fromJson(jsonData, SimpleTeam[].class);
27+
return simpleTeamArray;
28+
}
29+
30+
public static int[] toIntArray(String jsonData){
2131
int[] intArray = gson.fromJson(jsonData, int[].class);
2232
return intArray;
2333
}
2434

25-
public static DistrictEntry[] jsonToDistrictEntryArray(String jsonData){
26-
DistrictEntry[] districtEntryArray = gson.fromJson(jsonData, DistrictEntry[].class);
35+
public static District[] toDistrictEntryArray(String jsonData){
36+
District[] districtEntryArray = gson.fromJson(jsonData, District[].class);
2737
return districtEntryArray;
2838
}
2939

30-
public static Robot[] jsonToRobotArray(String jsonData){
40+
public static Robot[] toRobotArray(String jsonData){
3141
Robot[] robotArray = gson.fromJson(jsonData, Robot[].class);
3242
return robotArray;
3343
}
3444

35-
public static Event[] jsonToEventArray(String jsonData){
45+
public static Event[] toEventArray(String jsonData){
3646
Event[] eventArray = gson.fromJson(jsonData, Event[].class);
3747
return eventArray;
3848
}
3949

40-
public static SimpleEvent[] jsonToSimpleEventArray(String jsonData){
50+
public static SimpleEvent[] toSimpleEventArray(String jsonData){
4151
SimpleEvent[] eventArray = gson.fromJson(jsonData, SimpleEvent[].class);
4252
return eventArray;
4353
}
54+
55+
public static String[] toStringArray(String jsonData){
56+
String[] stringArray = gson.fromJson(jsonData, String[].class);
57+
return stringArray;
58+
}
59+
60+
public static Match[] toMatchArray(String jsonData){
61+
Match[] matchArray = gson.fromJson(jsonData, Match[].class);
62+
return matchArray;
63+
}
64+
65+
public static SimpleMatch[] toSimpleMatchArray(String jsonData){
66+
SimpleMatch[] matchArray = gson.fromJson(jsonData, SimpleMatch[].class);
67+
return matchArray;
68+
}
69+
70+
public static Award[] toAwardArray(String jsonData){
71+
Award[] awardArray = gson.fromJson(jsonData, Award[].class);
72+
return awardArray;
73+
}
74+
75+
public static Media[] toMediaArray(String jsonData){
76+
Media[] mediaArray = gson.fromJson(jsonData, Media[].class);
77+
return mediaArray;
78+
}
79+
80+
public static TeamEventStatus toTeamEventStatus(String jsonData){
81+
TeamEventStatus teamEventStatus = gson.fromJson(jsonData, TeamEventStatus.class);
82+
return teamEventStatus;
83+
}
84+
85+
public static DistrictRanking[] toDistrictRankingArray(String jsonData){
86+
DistrictRanking[] districtRankingArray = gson.fromJson(jsonData, DistrictRanking[].class);
87+
return districtRankingArray;
88+
}
89+
90+
public static EventDistrictPoints toEventDistrictPoints(String jsonData) {
91+
EventDistrictPoints eventDistrictPoints = gson.fromJson(jsonData, EventDistrictPoints.class);
92+
return eventDistrictPoints;
93+
}
94+
95+
public static EliminationAlliance[] toEliminationAllianceArray(String jsonContent) {
96+
EliminationAlliance[] eliminationAllianceArray = gson.fromJson(jsonContent, EliminationAlliance[].class);
97+
return eliminationAllianceArray;
98+
}
99+
100+
public static OPRs toOPRs(String jsonData) {
101+
OPRs oprs = gson.fromJson(jsonData, OPRs.class);
102+
return oprs;
103+
}
104+
105+
public static EventRankings toEventRankings(String jsonData) {
106+
EventRankings eventRankings = gson.fromJson(jsonData, EventRankings.class);
107+
return eventRankings;
108+
}
109+
110+
public static Match toMatch(String jsonData){
111+
Match match = gson.fromJson(jsonData, Match.class);
112+
return match;
113+
}
114+
115+
public static SimpleMatch toSimpleMatch(String jsonData){
116+
SimpleMatch match = gson.fromJson(jsonData, SimpleMatch.class);
117+
return match;
118+
}
44119

45120
}

src/main/java/com/thebluealliance/Main.java

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.thebluealliance;
2+
3+
import com.thebluealliance.requests.DataRequest;
4+
import com.thebluealliance.requests.DistrictRequest;
5+
import com.thebluealliance.requests.EventRequest;
6+
import com.thebluealliance.requests.MatchRequest;
7+
import com.thebluealliance.requests.TeamRequest;
8+
9+
public class TBA {
10+
11+
public static String AUTH_KEY;
12+
public final DataRequest dataRequest;
13+
public final TeamRequest teamRequest;
14+
public final EventRequest eventRequest;
15+
public final DistrictRequest districtRequest;
16+
public final MatchRequest matchRequest;
17+
18+
19+
public TBA(String authKey){
20+
AUTH_KEY = authKey;
21+
dataRequest = new DataRequest(AUTH_KEY);
22+
teamRequest = new TeamRequest(dataRequest);
23+
eventRequest = new EventRequest(dataRequest);
24+
districtRequest = new DistrictRequest(dataRequest);
25+
matchRequest = new MatchRequest(dataRequest);
26+
}
27+
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.thebluealliance.models;
2+
3+
public class Award {
4+
5+
private String name, event_key;
6+
private int award_type, year;
7+
private AwardRecipient[] recipient_list;
8+
9+
public class AwardRecipient{
10+
private String team_key, awardee;
11+
12+
public String getTeam_key() {
13+
return team_key;
14+
}
15+
16+
public String getAwardee() {
17+
return awardee;
18+
}
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public String getEventKey() {
26+
return event_key;
27+
}
28+
29+
public int getAwardType() {
30+
return award_type;
31+
}
32+
33+
public int getYear() {
34+
return year;
35+
}
36+
37+
public AwardRecipient[] getRecipientList() {
38+
return recipient_list;
39+
}
40+
41+
}

src/main/java/com/thebluealliance/models/DistrictEntry.java renamed to src/main/java/com/thebluealliance/models/District.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.thebluealliance.models;
22

3-
public class DistrictEntry {
3+
public class District {
44

55
private String abbreviation, display_name, key;
66
private int year;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.thebluealliance.models;
2+
3+
public class DistrictRanking {
4+
5+
private String teamKey;
6+
private int rank, rookie_bonus, point_total;
7+
private EventPoints event_points;
8+
9+
10+
11+
public String getTeamKey() {
12+
return teamKey;
13+
}
14+
15+
public int getRank() {
16+
return rank;
17+
}
18+
19+
public int getRookieBonus() {
20+
return rookie_bonus;
21+
}
22+
23+
public int getPointTotal() {
24+
return point_total;
25+
}
26+
27+
public EventPoints getEventPoints() {
28+
return event_points;
29+
}
30+
31+
}

0 commit comments

Comments
 (0)