Created
March 10, 2017 10:03
-
-
Save jackhftang/970853bee25b6245bbda80528dcc2e11 to your computer and use it in GitHub Desktop.
An easy google sheet for landing page
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
var SHEET_NAME = "Sheet1"; | |
function doGet(e) { | |
return handleResponse(e); | |
} | |
function doPost(e) { | |
return handleResponse(e); | |
} | |
function handleResponse(e) { | |
var lock = LockService.getPublicLock(); | |
lock.waitLock(30 * 1000); | |
try { | |
var doc = SpreadsheetApp.getActive(); | |
var sheet = doc.getSheetByName(SHEET_NAME); | |
var name = e.parameter.name; | |
var email = e.parameter.email; | |
if (!name) throw new Error('no name'); | |
if (!email) throw new Error('no email'); | |
sheet.appendRow([new Date(), name, email]); | |
return ContentService | |
.createTextOutput(JSON.stringify({"result": "success"})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} catch (e) { | |
return ContentService | |
.createTextOutput(JSON.stringify({"result": "error", "error": e})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} finally { | |
lock.releaseLock(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment