In order to make it easy for Java developers we have developed a class which we have made available to you.
You can download the a .jar file here, or alternatively you can download the full source of the Java here.
The JavaDoc for this class is available here.
Once you have add this library or code to your project, you may use the class as you can see below:
import org.json.JSONObject;
public class ApiExample {
/**
* @param args
*/
public static void main(String[] args) {
Api api = new Api("demouser", "demouser");
api.setDebugging(false);
String message_id = api.message_send("27111234567", "Hi there, I just sent a message!", "0214224825", null, null, null, null); /* Not all arguments are required */
if(message_id != null) {
System.out.println("It worked! Your message was sent!");
/* Now we can do some other checks */
Double balance = api.user_get_balance();
if(balance != null) {
System.out.println("Great! My balance is "+balance.toString());
}
JSONObject status = api.message_status(message_id);
if(status != null) {
try {
System.out.println("Message cost was "+String.valueOf(status.getDouble("cost")));
System.out.println("Message status is now "+String.valueOf(status.getInt("status")));
System.out.println("Message had "+String.valueOf(status.getInt("parts")) + " parts");
} catch(Exception e) {
System.out.println("JSON Error");
e.printStackTrace();
}
}
} else {
System.out.println("Could not send message
");
}
}
}
This class is based on the HTTP API.