Twizo Java API
Connect to the Twizo API using Java. This API includes functions to send verifications (2FA), SMS and Number Lookup.
Requirements
- Java >= 8
- Maven
Get application secret and api host
To use the Twizo API client, the following things are required:
- Create a Twizo account
- Login on the Twizo portal
- Find your application secret
- Find your nearest api node
Installation
At this moment there are 2 options to use the Twizo Java library (IntelliJ)
Maven
- Add Maven Framework to your project by right clicking the project folder -> Add Framework Support -> Maven
- Add the lib-api-java module module to your project
- Add the module as a dependency to your pom.xml file
<dependency>
<groupId>com.twizo</groupId>
<artifactId>lib-api-java</artifactId>
<version>0.1.0</version>
</dependency>
- Make sure to mark the src folder as source directory to be able to use the Twizo classes
- Reimport (or enable auto-import) Maven
Jar file
- Put the lib-api-java.jar file in your lib folder
- Add the library to the project in the Project Structure -> Libraries menu
In the near future this library will be available from the Maven Central Repository
Getting started
Initializing the Twizo Api using your api secret and api host
import com.twizo.TwizoFactory;
import com.twizo.Twizo;
class MyClass {
private static void main(String[] args) {
Twizo twizo = new TwizoFactory("your-api-key", Node.ASIA);
}
}
Send a sms
SmsController smsController = twizo.getSmsController();
// parameters = recipient phone number - message - sender phone number
smsController.sendSimple("60123456789", "Hello World", "60987654321");
Create a new NumberLookup
NumberLookupController numberLookupController = twizo.getNumberLookupController();
// parameter = phone number to look up
numberLookupController.createSimpleNumberLookup("60123456789");
Create a new Verification
VerificationController verificationController = twizo.getVerificationController();
// parameter = phone number to receive token
verificationController.createSimpleVerification("60123456789");
Verify a token
VerificationController verificationController = twizo.getVerificationController();
// parameter = token to verify
verificationController.verifyToken("012345");
Examples
In the examples directory you can find a collection of cli examples of how to use the api. When first running an example you will be asked for a host name and apiKey; this will be written to a properties file.
Testing
To run the Unit Tests provided with this code, you have to enter your API key in the TestSetup class in the tests directory.
License
The MIT License. Copyright (c) 2017 Twizo
Support
Contact: www.twizo.com — support@twizo.com