Skip to content

unimtx/uni-java-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unimatrix Java SDK

Maven Central Release GitHub license

The Unimatrix Java SDK provides convenient access to integrate communication capabilities into your Java applications using the Unimatrix HTTP API. The SDK provides support for sending SMS, 2FA verification, and phone number lookup.

Getting started

Before you begin, you need an Unimatrix account. If you don't have one yet, you can sign up for an Unimatrix account and get free credits to get you started.

Documentation

Check out the documentation at unimtx.com/docs for a quick overview.

Installation

The recommended way to install the Unimatrix SDK for Java is with a dependency management tool such as Maven or Gradle, which is available on Maven Central.

Maven users

Add this dependency to your project's pom.xml file:

<dependency>
    <groupId>com.unimtx</groupId>
    <artifactId>uni-sdk</artifactId>
    <version>0.3.0</version>
</dependency>

Gradle users

Add this dependency to your project's build.gradle file:

implementation "com.unimtx:uni-sdk:0.3.0"

Usage

The following example shows how to use the Unimatrix Java SDK to interact with Unimatrix services.

Initialization

import com.unimtx.Uni;

public class Example {
    private 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) {
        Uni.init(ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    }
}

or you can configure your credentials by environment variables:

export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret

Send SMS

Send a text message to a single recipient.

import com.unimtx.Uni;
import com.unimtx.UniException;
import com.unimtx.UniResponse;
import com.unimtx.model.UniMessage;

class Example {
    public static void main(String[] args) {
        Uni.init();

        UniMessage message = UniMessage.build()
            .setTo("+1206880xxxx") // in E.164 format
            .setText("Your verification code is 2048.");

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

Send verification code

Send a one-time passcode (OTP) to a recipient. The following example will send a automatically generated verification code to the user.

import com.unimtx.Uni;
import com.unimtx.UniResponse;
import com.unimtx.model.UniOtp;

class Example {
    public static void main(String[] args) {
        Uni.init();

        UniResponse res = UniOtp.build()
            .setTo("+1206880xxxx")
            .send();

        System.out.println(res.data);
    }
}

Check verification code

Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.

import com.unimtx.Uni;
import com.unimtx.UniResponse;
import com.unimtx.model.UniOtp;

class Example {
    public static void main(String[] args) {
        Uni.init();

        UniResponse res = UniOtp.build()
            .setTo("+1206880xxxx")
            .setCode("123456") // the code user provided
            .verify();

        System.out.println(res.valid);
    }
}

Reference

Other Unimatrix SDKs

To find Unimatrix SDKs in other programming languages, check out the list below:

License

This library is released under the MIT License.

About

The official Unimatrix SDK for Java.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages