Checking user balance using the Java API

  1. package com.panaceamobile;

  2.  

  3. import org.json.JSONObject;

  4.  

  5. public class ApiExample {

  6.  

  7. /**

  8. * @param args

  9. */

  10. public static void main(String[] args) {

  11. Api api = new Api("demouser", "demouser");

  12. api.setDebugging(false);

  13.  

  14. String message_id = api.message_send("0832659217", "Hi there, I just sent a message!", "0214224825", null, null, null, null); /* Not all arguments are required */

  15. if(message_id != null) {

  16. System.out.println("It worked! Your message was sent!");

  17.  

  18. /* Now we can do some other checks */

  19.  

  20. Double balance = api.user_get_balance();

  21. if(balance != null) {

  22. System.out.println("Great! My balance is "+balance.toString());

  23.  

    }

  24.  

  25. JSONObject status = api.message_status(message_id);

  26. if(status != null) {

  27. try {

  28. System.out.println("Message cost was "+String.valueOf(status.getDouble("cost")));

  29. System.out.println("Message status is now "+String.valueOf(status.getInt("status")));

  30. System.out.println("Message had "+String.valueOf(status.getInt("parts")) + " parts");

  31.  

  32. } catch(Exception e) {

  33. System.out.println("JSON Error");

  34. e.printStackTrace();

  35. }

  36. }

  37. } else {

  38. System.out.println("Could not send message :(");

  39. }

  40.  

  41. }

  42.  

  43. }