/
Game API integration documentation

Welcome to BigLedger Knowledge Center!

Game API integration documentation

Where to start?

Create DTO Request Class

First start by creating the DTO. These classes create the data objects which we will later be passing on to the services we create.

For example for Youzu, we have six fields which we need to pass to get the roles. Thus we create the DTO as following:

public final class YouzuGameRequest { private final String uid; private final String gid; private final String opid; private final String sid; private final String time; private String sign; public YouzuGameRequest(String uid, String gid, String opid, String sid, String time, String sign) { this.uid = uid; this.gid = gid; this.opid = opid; this.sid = sid; this.time = time; this.sign = sign; } public YouzuGameRequest withSign(String sign) { this.sign = sign; return this; } public String getUid() { return uid; } public String getGid() { return gid; } public String getOpid() { return opid; } public String getSid() { return sid; } public String getTime() { return time; } public String getSign() { return sign; } }

Note: Make sure the variable field names match the field names which should be passed to the third party API since the requests are going to be auto generated.

Also notice we only have getter methods and we mostly set the values in the constructure.

Add the request class to the general GameRequest class

We are using single endpoints for many game implementations and to implement this we have no choice but to have a generic GameRequest class which can accept different request objects.

As you see in the code snippet below, we added an instance of the YouzuGameRequest to this class. We also add the attributes inside the GameRequestBuilder class due to having a global controller API which should be able to accept different game requests.

public class GameRequest { private GarenaGameRequest garenagameRequest; private YouzuGameRequest youzuGameRequest; public static class GameRequestBuilder { //GARENA private String app_id; private String player_id; private String region; private String channel_name; //YOUZU private String uid; private String gid; private String opid; private String sid; private String sign; public GameRequestBuilder () { } ...

We have a separate builder for each game request which only assigns the relevant object before passing to the service. make sure you create a new builder for your game integration.

... private GameRequest buildGarenaRequest(GameRequestBuilder builder) { this.garenagameRequest = new GarenaGameRequest(builder.app_id, builder.player_id, builder.region, builder.channel_name); return this; } private GameRequest buildYouzuRequest(GameRequestBuilder builder) { final int time = (int) (new Date().getTime()/1000); this.youzuGameRequest = new YouzuGameRequest(builder.uid, builder.gid, builder.opid, builder.sid, String.valueOf(time), builder.sign); return this; } }

At the end add a new case for your implementation in the constructure so it could recognize which object to initialize.

 

Creating the Service

before you create the service you need to modify and add your integration to the handler.

Add new integration to GameTypeHandler

You will also need to add the new integration to the GameTypeHandler class so it could be defined and called in various places:

Adding New Service

The main logic relies in the service and it is mainly calling helper functions to do http get or post inquiries from the API’s provided by different game developers. Thus all you need to do is to extend GameClientService and add the code for doing the inquiries:

Special Configurations

If your implementation has a special configuration, for example you need to use an Api Key to sign the requests you send. Then you can retrieve that configuration from App Config table using the AppCfgMainUow() unit of work service.

For example the following code reads the api_key for Youzu integration.

These configurations should be manually saved in the app_cfg_main database:

They are queried using txn_type column and thus the id you use in this column should be the same as the one used in your GameTypeHandlerGameTypes.

Adding in the Controller

The Controller serves the endpoint for calling the API, for getting info about a gamer you can use GET methods. You wont need to make any changes in this class as long as you have properly set the handler and GameRequest class.

For example the following request is for a Youzu user:

While the next one is a for a Garena user:

Notice that the parameters passed and the game type are differently defined in each

Powered by: Bigledger Sdn Bhd