Skip to content

Instantly share code, notes, and snippets.

@jparreira
Created April 8, 2015 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jparreira/f74d5b4e403c191b5d5f to your computer and use it in GitHub Desktop.
Save jparreira/f74d5b4e403c191b5d5f to your computer and use it in GitHub Desktop.
Retrieving todo items from Realtime Cloud Storage using the REST API from Appcelerator Titanium. This sample can be used with http://storage-public.realtime.co/samples/todo-lbl/index.html#/
//UI
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var label1 = Titanium.UI.createLabel({
color:'#777',
text:'Connecting to Realtime Storage...',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win1.add(label1);
win1.open();
//Connection
var body = {
table: "todoTable",
key: {
primary: "storage-demo"
},
searchForward: true,
applicationKey: "2Ze1dz",
authenticationToken: "TodoRealtimeStorage"
};
var hClient = Ti.Network.createHTTPClient({
onload : function() {
label1.text = 'Items:\n\n'+JSON.parse(this.responseText).data.items.map(function(i){return JSON.stringify(i);}).join('\n\n');
},
onerror : function(e) {
label1.text('An error has occured... ' + e);
},
timeout : 5000 // in milliseconds
});
hClient.open("POST", 'https://storage-backend-prd-useast1.realtime.co/queryItems');
hClient.setRequestHeader('Content-Type', 'application/json');
hClient.send(JSON.stringify(body));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment