Log in

View Full Version : Implementing TBA Api in Java


ceb515
14-03-2015, 14:12
Okay guys I need some help:confused: ,
I'm creating a Java Program and I want it to be able to access match data from TBA and store it somewhere.

I have absolutely NO idea how to access the data from the API or how to store or display (JFrame) the data.

Any help or suggestions?

Jon Stratis
14-03-2015, 14:32
Why use the Blue Alliance API and not the official FIRST API that the Blue Alliance most likely uses to populate their own data? You can find out more about the FIRST Event API on their TeamForge page: https://usfirst.collab.net/sf/projects/first_community_developers/

If you decide to go that route, get signed up and I can share some of the work I've done with you... It's all in Java, designed to pull all of the data needed to calculate rankings for the MN State Championship invites - basically, a slightly modified version of the District ranking formula. It would at least give you a framework for making requests and parsing the results.

Past that, you'll have to decide what your requirements are for storing and displaying data. On the complex side of things, you could read all of the data into a database, and run a local webhost to put it in a browser, or a local app customized to display and navigate the data. On the easy side, you could spit it out into a CSV file and open it in Excel to play around with. In the middle, you can actually write the data directly to a nicely formatted, multi-tab spreadsheet (there's an apache library (http://poi.apache.org/spreadsheet/) that makes this relatively easy to do, once you get it figured out). This is one of the things I love most about programming... there are a hundred ways to do what you want, you just have to decide which way to use!

ceb515
14-03-2015, 14:40
Okay so I created an account on TeamForge, how would you like to share the code that you currently have?

-Charlie

Ether
14-03-2015, 16:29
Why use the Blue Alliance API and not the official FIRST API that the Blue Alliance most likely uses to populate their own data?

If your goal is to a) write an app that uses FRC's API and b) share that app widely... you may want to get FIRST's approval before you do so.

ceb515
14-03-2015, 16:30
If your goal it to a) write an app that uses FRC's API and b) share that app widely... you may want to get FIRST's approval before you do so.




My purpose is to make an app to use for myself and for my team, I would go to first before I go widespread

Ether
14-03-2015, 16:33
...and for my team

This token is meant for personal development, if you intend to use it for any significant volume, you must inform us and associated an organization and contact information or the token will be disabled.
.
.
.

Jon Stratis
14-03-2015, 17:28
Each registered user/team gets a unique token that's used on every request - in other words, if you spam the server a ridiculous amount (for example, sticking it in an app like FRC Spyder and having every client hit the FRC servers) then FIRST can identify the offending developer and work with them to reduce the impact on the FRC servers (for example, by periodic polling of the servers and storage of results on a 3rd party server for further distribution from there).

Once FIRST accepts you in the group and issues you a token, message me on TeamForge and I'll send you some stuff to get you started there.

plnyyanks
14-03-2015, 18:11
Okay guys I need some help:confused: ,
I'm creating a Java Program and I want it to be able to access match data from TBA and store it somewhere.

I have absolutely NO idea how to access the data from the API or how to store or display (JFrame) the data.

Any help or suggestions?


If you still want to see a Java implementation of the TBA API, the Android app implements all the endpoints. You can check out the code here https://github.com/the-blue-alliance/the-blue-alliance-android

plnyyanks
14-03-2015, 21:36
Here's a little more detailed info about the TBA API, now that I'm no longer trying to keep a regional on schedule...

The TBA API is pretty fully featured - it's got a lot of data you can pull in multiple ways. The simplest is the main API (documentation is here (http://www.thebluealliance.com/apidocs)). You hit a url for the data you want, and get a response back. This is what the TBA Android app implements for its data source. Here are some links to getting started:
- Where API urls are built (https://github.com/the-blue-alliance/the-blue-alliance-android/blob/master/android/src/main/java/com/thebluealliance/androidclient/datafeed/TBAv2.java#L83)
- Where the HTTP Request is built (https://github.com/the-blue-alliance/the-blue-alliance-android/blob/master/android/src/main/java/com/thebluealliance/androidclient/datafeed/TBAv2.java#L83)
- All the model deserializers (https://github.com/the-blue-alliance/the-blue-alliance-android/tree/master/android/src/main/java/com/thebluealliance/androidclient/datafeed/deserializers) (to bring the json response into Java objects). I've been meaning to rip this out and make it into a library we can publish on maven central for other people to use, but that'll happen when I get the time...

TBA can also push live updates to a server of your choosing (documentation is here (http://www.thebluealliance.com/apidocs/webhooks)). This is how the Android app handles its push notifications. You subscribe your account to whatever you want (teams, events, everything, etc) and pick the notification types you would like to receive updates for, and TBA will push a POST request to a server you've registered every time something updates.

Here is an example project (https://github.com/the-blue-alliance/the-blue-alliance-notification-firehose) that implements a webhook receiver, and here specifically (https://github.com/the-blue-alliance/the-blue-alliance-notification-firehose/blob/master/main.py#L55) is where webhooks come in