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;
@fakada
Copy link

fakada commented Sep 6, 2013

Hi Aron,

First thanks for the snippet...
Can you explain how to use this ? I've put your code at app/lib and named it ti-parse.js, and also put there the parse-1.2.10.js

Then on a controller (eg: index.js) I put

var Parse = require('ti-parse');
var Myobject = Parse.Object.extend("Myobject");

but this returns error:

undefined' is not an object (evaluating 'Parse.Object') ...

Can you help?

@iantearle
Copy link

Try and route out parse-1.2.7.js - new versions have some elements that do not get "titaniumified" by this script.

@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