Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
Divyanshu Sharma edited this page Feb 6, 2020 · 12 revisions

Welcome to the pw4j wiki!

Adding to your Java project

Use the latest version from https://github.com/l0llygag/pw4j/packages in your build tool.

For adding the wrappers as Jars/libraries, download the JAR from releases. AND add GSON v2.8.5 JAR from maven central to your path/libraries.

Basic Usage

To start using the wrapper, build a PoliticsAndWar object using PoliitcsAndWarBuilder. If you want to access any endpoint, you'll need to provide the apiKey. Not providing an apiKey will result in a PoliticsAndWarException being thrown.

PoliticsAndWar politicsAndWar = new PoliticsAndWarBuilder().addApiKey("YOUR_API_KEY_STRING").build();

To use the Test server API,

PoliticsAndWar politicsAndWar = new PoliticsAndWarBuilder().addApiKey("YOUR_API_KEY_STRING").setTestServerMode(true).build();

That was the hardest part. 😅

Now you can get a Nation with

politicsAndWar.getNation(6); //Where 6 is Nation Id

or

politicsAndWar.getBank(913); //Where 913 is Alliance ID

NOTE: This a in-memory wrapper for the API and does not communicate with any external service other than the API itself. Nor does it store any kind of information permanently at an external or even local location. (Everything dies with your program)

Advanced Usage

The wrapper has an inbuilt cache client to process APIs faster. It can store a certain amount of calls for a certain amount of time. This is disabled by default.

Instantiate the object this way to change enable/change settings:

PoliticsAndWar politicsAndWar = new PoliticsAndWarBuilder().setEnableCache(true,cacheSize,cacheRetainTime).build();

cacheSize is the limit of the number of API requests to cache. cacheRetainTime is the time (in milliseconds) for which an API request should be stored.

NOTE: Default values for cachSize is 50 & cacheRetainTime is 6000. Not providing both parameters will use the default values.

PoliticsAndWar politicsAndWar = new PoliticsAndWarBuilder().setEnableCache(true).build();

How does this work?

Example: cacheSize = 100 and cacheRetainTime = 30000

The following setting will mean... "Store the last 100 requests made in last 30s". So if you made 101 requests in the last 30s... then the 1st request will be "expired" from the cache and will be updated with the new data.

Clone this wiki locally