Update Nov2017
UPDATE: parse.com as now been closed and moved to parseplatform.org. I will update the content of this page an move the back-end to this platform
The source data colorTable we want to load to our parse.com database is currently in a Google Spreadsheet. With scriptDB, we can access it directly. However, to load data into parse we need to use the google visualization query API, since we are doing this from a javaScript app.
Here’s how to use the Google Viz API along with jQuery promises. Since getting the current contents of parse and this are async, we can do them at the same time – using promises to sync up when done.
function doTheWork () { // get the data from google apps script - async var dataFromGoogle = getColorTable(); dataFromGoogle.fail( function(error) { $("#data").text("error getting google docs data " + error); }); //get current parse data for scheme - async var scheme = ""; var parseKeys = getParseKeys(); Parse.initialize(parseKeys.appId, parseKeys.jsKey); var ColorTable = Parse.Object.extend("ColorTable"); var schemeFromParse = schemePromise(ColorTable, scheme); schemeFromParse.fail(function (error) { $("#scheme").text("error getting scheme " + scheme + JSON.stringify(error)); }); // now we can get going schemeFromParse.done(function (all) { $("#scheme").text("scheme " + scheme + " returned " + all.length); dataFromGoogle.done(function(data) { $("#data").text("data back from gapps"); // start work... }); }); } function getColorTable() { var deferred = $.Deferred(); var workBook = 'http://docs.google.com/spreadsheet/tq?key=0At2ExLh4POiZdGFnVFJEQkpRSXZWYUF2WmF6ZUliU3c'; var sheet ='&sheet=colorTable'; var headers = '&headers=1'; var query = new google.visualization.Query(workBook + sheet + headers); // get 1st 5 columns query.setQuery('SELECT A,B,C,D,E options no_format'); // assume its big query.setTimeout(200); // Send the query with a callback function. query.send(function (response) { if (response.isError()) deferred.reject('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); else deferred.resolve(response.getDataTable()); }); return deferred.promise(); }
For more on parse.com see Parse.com
For help and more information join our forum, follow the blog or follow me on Twitter