Skip to content

Instantly share code, notes, and snippets.

@kylecorry31
Last active October 11, 2016 00:41
Show Gist options
  • Save kylecorry31/181d80421a85deb96973c1cb1824d96b to your computer and use it in GitHub Desktop.
Save kylecorry31/181d80421a85deb96973c1cb1824d96b to your computer and use it in GitHub Desktop.
Simple Google Sheets API for JS
function Sheet(key){
this.key = key;
this.baseurl = "https://spreadsheets.google.com/pub?key="+this.key+"&hl=en&output=tsv";
}
Sheet.prototype.fetchAsync = function(pageId, callback){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(_getSheetData(xmlHttp.responseText));
}
xmlHttp.open("GET", this.baseurl + "&gid=" + pageId, true);
xmlHttp.send(null);
}
function _getSheetData(responseText){
return responseText.split('\n').map(function(row){
return row.split('\t');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment