Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Last active November 14, 2018 18:00
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronksaunders/4742657 to your computer and use it in GitHub Desktop.
Save aaronksaunders/4742657 to your computer and use it in GitHub Desktop.
//
// See Slidedeck for more information
//
// http://www.slideshare.net/aaronksaunders/parse-appcelerator-titanium-the-easy-way-jan2013
//
// Aaron K Saunders
// Clearly Innovative Inc
//
// twitter : @aaronksaunders
// blog : blog.clearlyinnovative.com
//
var TiParse = require("tiparse")();
var TestObject = TiParse.Object.extend("TestObject");
var testObject = new TestObject();
testObject.save({
foo : "bar"
}, {
success : function(object) {
Ti.API.info("yay! it worked");
createUser()
},
error : function(object, error) {
// Show the error message somewhere and let the user try again.
Ti.API.info("Error: " + error.code + " " + error.message);
}
});
//
// CREATE USER
//
//
// LOGIN USER
//
function testUserLogin(_user) {
Parse.User.logIn(_user.get("username"), _user.get("password"), {
success : function(user) {
// Do stuff after successful login.
Ti.API.info("yay! logIn worked " + JSON.stringify(user));
},
error : function(user, error) {
// Show the error message somewhere and let the user try again.
Ti.API.info("Error: " + error.code + " " + error.message);
}
});
}
function createUser() {
var user = new TiParse.User();
user.set("username", "my name");
user.set("password", "my pass");
user.set("email", "email@example.com");
// other fields can be set just like with Parse.Object
user.set("phone", "415-392-0202");
user.signUp(null, {
success : function(_user) {
// Hooray! Let them use the app now.
Ti.API.info("yay! signUp worked " + JSON.stringify(user));
testUserLogin(user);
},
error : function(_user, error) {
// Show the error message somewhere and let the user try again.
Ti.API.info("Error: " + error.code + " " + error.message); debugger;
testUserLogin(user);
}
});
}
var TiParse = function(options) {
Ti.include("parse-min.js");
Parse.localStorage = {
getItem: function(_key) {
return Ti.App.Properties.getObject(_key);
},
setItem: function(_key, _value) {
return Ti.App.Properties.setObject(_key, _value);
},
removeItem: function(_key, _value) {
return Ti.App.Properties.removeProperty(_key);
}
};
Parse._ajax = function(method, url, data, success, error) {
var handled = !1, xhr = Ti.Network.createHTTPClient({
timeout: 5000
});
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (handled) return;
handled = !0;
if (xhr.status >= 200 && xhr.status < 300) {
var response;
try {
response = JSON.parse(xhr.responseText);
} catch (e) {
error && error(xhr);
}
response && success && success(response, xhr);
} else error && error(xhr);
}
};
xhr.open(method, url, !0);
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.send(data);
};
Parse.initialize("KEYS", "KEYS");
return Parse;
};
module.exports = TiParse;
@Psiiirus
Copy link

Hiya,
I was thinking of building an app with the open-source versions of titanium+alloy and parse.com-server.

Do you think this is a good idea or is this combination already outtdated and "dead"?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment