Java SDK

Install

The Uni Java SDK is hosted by Maven and is available from the public Maven repository.

Add the Maven dependency to the project using the following code:

<dependency>
    <groupId>com.apistd.uni</groupId>
    <artifactId>uni-sdk</artifactId>
    <version>0.0.4</version>
</dependency>

or use Gradle:

implementation "com.apistd.uni:uni-sdk:0.0.4"

Usage

The following example shows how to use the Uni Java SDK to quickly invoke a service.

Send an SMS


import com.apistd.uni.Uni;
import com.apistd.uni.UniException;
import com.apistd.uni.UniResponse;
import com.apistd.uni.sms.UniSMS;
import com.apistd.uni.sms.UniMessage;

import java.util.HashMap;
import java.util.Map;

public class Example {
    public static String ACCESS_KEY_ID = "your access key id";
    private static String ACCESS_KEY_SECRET = "your access key secret";

    public static void main(String[] args) {
        // initialization
        Uni.init(ACCESS_KEY_ID, ACCESS_KEY_SECRET); // if you use the simple auth mode, just pass in the first parameter
        Uni.setEndpoint("https://api.unimtx.com"); // set endpoint

        // set custom parameters (variable SMS)
        Map<String, String> templateData = new HashMap<String, String>();
        templateData.put("code", "6666");

        // build a message
        UniMessage message = UniSMS.buildMessage()
            .setTo("your phone number")
            .setSignature("Unimatrix")
            .setTemplateId("pub_verif_basic")
            .setTemplateData(templateData);

        // send the message
        try {
            UniResponse res = message.send();
            System.out.println(res);
        } catch (UniException e) {
            System.out.println("Error: " + e);
            System.out.println("RequestId: " + e.requestId);
        }
    }
}