Created
March 27, 2020 17:36
-
-
Save gentunian/17362eb0ad253a5160144595e1112804 to your computer and use it in GitHub Desktop.
I think we should change the name :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* var foo = new SpreadShitter({ | |
* sheetId: <this id is in the spreadsheet url>, | |
* googleApiKey: <any google api key>}); | |
* var sheetName = "My sheet"; | |
* var range ="!A1:A2"; | |
* foo.getValue(sheetName, range, function(data, errorEvent) { | |
* // handle logix here... | |
* }) | |
* @type {SpreadShitter} | |
*/ | |
window.SpreadShitter = (function() { | |
function SpreadShitter(options) { | |
this.googleSheetsApiUrl = "https://sheets.googleapis.com/v4/spreadsheets"; | |
this.sheetId = options.sheetId; | |
this.googleApiKey = options.googleApiKey; | |
this.getValue = function(sheetName, range, callback) { | |
var request = new XMLHttpRequest(); | |
request.addEventListener("load", function(e) { | |
callback.call(this, this.responseText); | |
}); | |
request.addEventListener("error", function(e) { | |
callback.call(this, undefined, e); | |
}); | |
var url = new URL([ | |
this.googleSheetsApiUrl, | |
this.sheetId, | |
"values", | |
sheetName + range | |
].join("/")); | |
url.searchParams.append("key", this.googleApiKey); | |
request.open("GET", url.href); | |
request.send(); | |
} | |
} | |
return SpreadShitter | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage