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 1 You must be signed in to fork a gist
  • Save aaronksaunders/5443666 to your computer and use it in GitHub Desktop.
Save aaronksaunders/5443666 to your computer and use it in GitHub Desktop.
Tested w/ latest version of parse "parse-1.2.7.js"
var TiParse = function(options) {
// need to convert this to requires
Ti.include("parse-1.2.7.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 options = {
success: success,
error: error
};
var promise = new Parse.Promise, 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) {
promise.reject(e);
}
response && promise.resolve(response, xhr.status, xhr);
} else promise.reject(xhr);
}
};
xhr.open(method, url, !0);
xhr.setRequestHeader("Content-Type", "text/plain");
Parse._isNode && xhr.setRequestHeader("User-Agent", "Parse/" + Parse.VERSION + " (NodeJS " + process.versions.node + ")");
xhr.send(data);
return promise._thenRunCallbacks(options);
};
Parse.initialize("Application ID", "JavaScript key");
return Parse;
};
module.exports = TiParse;
@aaronksaunders
Copy link
Author

updated gist here http://bit.ly/16rKE77 this should work with the most recent version of the parse SDK

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