Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyApp extends Activity
- {
- public Trestle Tr = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Tr = new Trestle("appId", "appClientKey");
- // This is a very simple example of the Trestle Chain server.
- // This should give you an idea of the possibilities when using the Chain server.
- // Clear the Chain buffer in case there was a previously executed chain
- Tr.StartNewChain();
- // Create a chain post operation as link1
- JSONObject data1 = new JSONObject();
- data1.put("field1","value1");
- data1.put("field2","value2");
- Tr.ChainPost("link1", "v1/object/mycol", data1);
- // Add a conditional for link2
- JSONObject cif = new JSONObject();
- cif.put("type","if");
- cif.put("comparison","link1->results->code eq 201");
- Tr.AddCondition(cif);
- // link2 will only be executed if the 'cif' conditional is true
- JSONObject data2 = new JSONObject();
- data2.put("field3","value3");
- Tr.ChainPost("link2", "v1/object/mycol", data2);
- // close the conditional..
- JSONObject cendif = new JSONObject();
- cendif.put("type","endif");
- cendif.put("comparison","true");
- Tr.AddCondition(cendif);
- // link3 uses Trestle's geo service
- Tr.ChainGet("link3","v1/geo/65.52.33.4",null);
- // Now execute the chain, sending all the links and conditionals as one batch
- Tr.ChainExecute( new TrestleResponseDelegate() {
- public void Response(JSONObject response) throws Exception {
- if(response.getInt("code") == 200) {
- Log.d("Trestle","Done");
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment