Skip to content
TORNLIFE More

Java Torn API Wrapper [Under Development]

Started by UwU [2081212] on in API Development.

8 replies · 220 views · thread synced · 7 days ago · View on torn.com
About this thread

Posts archived: 9 / 9 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
9
Discussion span
→
People posting
4
Likes on archived posts
7
Authority score
52 / 100
Historical score
29 / 100
Story score
40 / 100
Engagement score
55 / 100
UwU [2081212]

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
Market Selections
  • Item Market
  • Points Market
  • Bazaar Market
Faction Selections
  • Basic
  • Chain
  • Stats
  • Main News
  • Attack News
  • Armory News
  • Donation News
Torn Selections
  • Stock Market
As time goes on I'll progressively add the missing sections. Also, there are a lot more existing features buried within those selections such as easy access to items in the market and sorting that I'll cover if there's interest.

 

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.
Shane [1514924]

How easy would this be to use in an Android app? 

I made one for a college assignment but didn't use a library, just used retrofit for the API calls, im a Java noob, normally use .Net

Looking really good though!
UwU [2081212]

Thanks.

As for your question I'd say very easy. This is designed to be added to any Java project as an external library. To show you what I mean have a look at the following screenshot.

The program structure to the left shows what it'd look like in general. You just need to import the .jar as a dependency and away you go.

The three lines inside the red box is the minimum work you need to do to make an API call. Considering this is Java I think it's an impressive reduction of code. Of course if you're doing a multi-selection call then that will require a couple more lines.

The rest is just manipulating the data however you wish.

[image: i68.tinypic.com]

 
Aezur [1950769]

 Is there a public repo for this? Ive been looking for a new project to tinker with. I could help you finish it. 
UwU [2081212]
Unfortunately that’s an unsolvable problem I think. Up to my knowledge the API doesn’t support this.
Adrenalinas [1974447]
It can be solved easily with API rotation if multi acc would be legal :D still it sucks ched don`t support bigger requests if he do at least 5 items per request that would work much better
UwU [2081212]
I’d love the ability to purchase or rent more calls.

Ched could set it up to be rented with in game cash maybe? Would provide another money sink.

I’d be first in line to rent more call slots with my api key.

Although Ched did mention a revamp of the API that might solve this issue of needing to repeatedly make calls. I highly doubt it’ll be changed anytime soon though.