Skip to content

Instantly share code, notes, and snippets.

@csemrm
Created December 29, 2013 14:55
Show Gist options
  • Save csemrm/8171168 to your computer and use it in GitHub Desktop.
Save csemrm/8171168 to your computer and use it in GitHub Desktop.
Titanium ACS Create post objects with custom object in Ti ACS
var Cloud = require('ti.cloud');
Cloud.debug = true;
var win = Ti.UI.createWindow({
backgroundColor : 'white',
});
var post_photo = Ti.UI.createButton({
title : 'event query',
top : 20,
});
login();
function login() {
Cloud.Users.login({
login : 'username',
password : 'password'
}, function(e) {
if (e.success) {
currentUser = e.users[0];
loggedIn = true;
alert('login Success');
create_event();
} else {
Ti.API.info('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
loggedIn = false;
currentUser = null;
}
});
}
var googleReverseGeo = {
"results" : [{
"address_components" : [{
"long_name" : "365-11",
"short_name" : "365-11",
"types" : ["political"]
}, {
"long_name" : "Sindorim-dong",
"short_name" : "Sindorim-dong",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Guro-gu",
"short_name" : "Guro-gu",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}, {
"long_name" : "152-070",
"short_name" : "152-070",
"types" : ["postal_code"]
}],
"formatted_address" : "365-11 Sindorim-dong, Guro-gu, Seoul, South Korea",
"geometry" : {
"location" : {
"lat" : 37.5096051,
"lng" : 126.8872816
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.5184557,
"lng" : 126.903289
},
"southwest" : {
"lat" : 37.5007535,
"lng" : 126.8712742
}
}
},
"types" : ["political"]
}, {
"address_components" : [{
"long_name" : "Sindorim-dong",
"short_name" : "Sindorim-dong",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Guro-gu",
"short_name" : "Guro-gu",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}, {
"long_name" : "152-070",
"short_name" : "152-070",
"types" : ["postal_code"]
}],
"formatted_address" : "Sindorim-dong, Guro-gu, Seoul, South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
},
"location" : {
"lat" : 37.509469,
"lng" : 126.882105
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
}
},
"types" : ["sublocality", "political"]
}, {
"address_components" : [{
"long_name" : "Sindorim-dong",
"short_name" : "Sindorim-dong",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Guro-gu",
"short_name" : "Guro-gu",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}, {
"long_name" : "152-070",
"short_name" : "152-070",
"types" : ["postal_code"]
}],
"formatted_address" : "Sindorim-dong, Guro-gu, Seoul, South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
},
"location" : {
"lat" : 37.5077345,
"lng" : 126.8805914
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
}
},
"types" : ["sublocality", "political"]
}, {
"address_components" : [{
"long_name" : "152-070",
"short_name" : "152-070",
"types" : ["postal_code"]
}, {
"long_name" : "Sindorim-dong",
"short_name" : "Sindorim-dong",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Guro-gu",
"short_name" : "Guro-gu",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}],
"formatted_address" : "Sindorim-dong, Guro-gu, Seoul, South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
},
"location" : {
"lat" : 37.5114119,
"lng" : 126.8815276
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.8922686
},
"southwest" : {
"lat" : 37.5031568,
"lng" : 126.873054
}
}
},
"types" : ["postal_code"]
}, {
"address_components" : [{
"long_name" : "Guro-gu",
"short_name" : "Guro-gu",
"types" : ["sublocality", "political"]
}, {
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}],
"formatted_address" : "Guro-gu, Seoul, South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.9030494
},
"southwest" : {
"lat" : 37.4733012,
"lng" : 126.8126901
}
},
"location" : {
"lat" : 37.4954031,
"lng" : 126.887369
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.5182288,
"lng" : 126.9030494
},
"southwest" : {
"lat" : 37.4733012,
"lng" : 126.8126901
}
}
},
"types" : ["sublocality", "political"]
}, {
"address_components" : [{
"long_name" : "Seoul",
"short_name" : "Seoul",
"types" : ["locality", "political"]
}, {
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}],
"formatted_address" : "Seoul, South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.7017495,
"lng" : 127.18359
},
"southwest" : {
"lat" : 37.4259627,
"lng" : 126.7645827
}
},
"location" : {
"lat" : 37.566535,
"lng" : 126.9779692
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.6956,
"lng" : 127.1823
},
"southwest" : {
"lat" : 37.4346,
"lng" : 126.7968
}
}
},
"types" : ["locality", "political"]
}, {
"address_components" : [{
"long_name" : "South Korea",
"short_name" : "KR",
"types" : ["country", "political"]
}],
"formatted_address" : "South Korea",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 38.6169312,
"lng" : 130.9232178
},
"southwest" : {
"lat" : 33.1061096,
"lng" : 124.608139
}
},
"location" : {
"lat" : 35.907757,
"lng" : 127.766922
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 38.6169312,
"lng" : 129.584671
},
"southwest" : {
"lat" : 33.1061096,
"lng" : 124.608139
}
}
},
"types" : ["country", "political"]
}],
"status" : "OK"
};
function create_event() {
Cloud.Posts.create({
content : 'Man Walks On Moon',
title : 'News of the day',
custom_fields : googleReverseGeo
}, function(e) {
if (e.success) {
var post = e.posts[0];
Cloud.Posts.show({
post_id : post.id
}, function(e) {
if (e.success) {
var post = e.posts[0];
alert('id: ' + post.id + '\n' + 'custom_fields: ' + JSON.stringify(post.custom_fields));
} else {
alert('SHOW Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
post_photo.addEventListener('click', function() {
Cloud.Posts.query({
page : 1,
per_page : 1,
}, function(e) {
if (e.success) {
Ti.API.info('Success:\n' + 'Count: ' + e.posts.length);
for (var i = 0; i < e.posts.length; i++) {
var post = e.posts[i];
alert('id: ' + post.id + '\n' + 'custom_fields: ' + JSON.stringify(post.custom_fields));
}
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
});
win.add(post_photo);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment