Just wondering if there's any interest out there for a comprehensive Java-based wrapper for the Torn API.
Reason why I'm asking is because I've developed one with several public selections already implemented, but I haven't added any documentation on how to use it apart from comments within the code.
If there's any interest I'd be happy to work on some public documentation and release an .jar file that you can as an external library. In return feedback on wrapper features or implementations would be greatly appreciated.
The main purpose of the wrapper was to remove all the code needed to manage connections and process the returned JSON data from the applications/services I develop so the result is code that's much easier to read and manage.
To give you an idea of what your code would be like using the wrapper here's a few simple examples:
Create the API Key object
KeyBean keyBean = new KeyBean();
keyBean.setApiKey("keyHere");
The reason why a custom key object is used is because it also has internal mechanisms that limit the API key from being overused. The interval times are also customizable (measured in milliseconds).
Retrieve someone's profile
Profile profile = UserSelections.getProfile(keyBean, userId);
Getting multiple selections within a category with only one API call
List selections = Arrays.asList("profile", "personalstats", "bazaar");
HashMap mappedSelections = UserSelections.getMultipleSelections(keyBean, selections, userId);
Profile profile = (Profile) mappedSelections.get("profile");
PersonalStats personalStats = (PersonalStats) mappedSelections.get("personalstats");
Bazaar bazaar = (Bazaar) mappedSelections.get("bazaar");
That's pretty much all you need to do. All the heavy lifting is done within the wrapper and it'll return the results you need. Next thing to do is just grab the data you need which is as simple as:
System.out.println(profile.getName() + "'s current life is: " + profile.getCurrentLife() + " / " + profile.getMaximumLife());
[image: media.discordapp.net]
So far the following categories and the associated selections have been implemented:
User Selections
- Profile
- Personal Stats (All stats are accessible including the more recently added ones)
- Bazaar
- Item Market
- Points Market
- Bazaar Market
- Basic
- Chain
- Stats
- Main News
- Attack News
- Armory News
- Donation News
- Stock Market
There are also some side features being developed such as a KeyManager class. This feature isn't a huge priority since I won't need it for another month or two, but I've already implemented some methods to test the idea.
Imagine you're running a service and have a database of API keys. You could get them and store them in an list and use the manager to sort the API keys for you.
KeyBean keyToUseNext = KeyManager.getFirstAvailableKey(keyBeans); // Just grab the first available key in the list
or
KeyBean keyToUseNext = KeyManager.getLeastUsedKey(keyBeans); // Get the key that hasn't been used the longest
I personally use this wrapper. Well the original wrapper, but will begin migrating my applications to use this one next week so you can expect that it'll remain under active development.