Checking user balance using the Java API


  1. package com.panaceamobile;

  2. import org.json.JSONObject;

  3. public class ApiExample {

  4. /**
  5. * @param args
  6. */
  7. public static void main(String[] args) {
  8. Api api = new Api("demouser", "demouser");
  9. api.setDebugging(false);

  10. String message_id = api.message_send("0832659217", "Hi there, I just sent a message!", "0214224825", null, null, null, null); /* Not all arguments are required */
  11. if(message_id != null) {
  12. System.out.println("It worked! Your message was sent!");

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

  14. Double balance = api.user_get_balance();
  15. if(balance != null) {
  16. System.out.println("Great! My balance is "+balance.toString());
  17. }

  18. JSONObject status = api.message_status(message_id);
  19. if(status != null) {
  20. try {
  21. System.out.println("Message cost was "+String.valueOf(status.getDouble("cost")));
  22. System.out.println("Message status is now "+String.valueOf(status.getInt("status")));
  23. System.out.println("Message had "+String.valueOf(status.getInt("parts")) + " parts");

  24. } catch(Exception e) {
  25. System.out.println("JSON Error");
  26. e.printStackTrace();
  27. }
  28. }
  29. } else {
  30. System.out.println("Could not send message :(");
  31. }

  32. }

  33. }