Guest User

Untitled

a guest
Sep 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public class MyApp extends Activity
  2. {
  3. public Trestle Tr = null;
  4.  
  5. @Override
  6. public void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. Tr = new Trestle("appId", "appClientKey");
  9.  
  10. // This is a very simple example of the Trestle Chain server.
  11. // This should give you an idea of the possibilities when using the Chain server.
  12.  
  13. // Clear the Chain buffer in case there was a previously executed chain
  14. Tr.StartNewChain();
  15.  
  16. // Create a chain post operation as link1
  17. JSONObject data1 = new JSONObject();
  18. data1.put("field1","value1");
  19. data1.put("field2","value2");
  20. Tr.ChainPost("link1", "v1/object/mycol", data1);
  21.  
  22. // Add a conditional for link2
  23. JSONObject cif = new JSONObject();
  24. cif.put("type","if");
  25. cif.put("comparison","link1->results->code eq 201");
  26. Tr.AddCondition(cif);
  27. // link2 will only be executed if the 'cif' conditional is true
  28. JSONObject data2 = new JSONObject();
  29. data2.put("field3","value3");
  30. Tr.ChainPost("link2", "v1/object/mycol", data2);
  31. // close the conditional..
  32. JSONObject cendif = new JSONObject();
  33. cendif.put("type","endif");
  34. cendif.put("comparison","true");
  35. Tr.AddCondition(cendif);
  36.  
  37. // link3 uses Trestle's geo service
  38. Tr.ChainGet("link3","v1/geo/65.52.33.4",null);
  39.  
  40. // Now execute the chain, sending all the links and conditionals as one batch
  41. Tr.ChainExecute( new TrestleResponseDelegate() {
  42. public void Response(JSONObject response) throws Exception {
  43. if(response.getInt("code") == 200) {
  44. Log.d("Trestle","Done");
  45. }
  46. }
  47. });
  48. }
Add Comment
Please, Sign In to add comment