Skip to content

Instantly share code, notes, and snippets.

@edom18
Created January 19, 2014 12:44
Show Gist options
  • Save edom18/8504399 to your computer and use it in GitHub Desktop.
Save edom18/8504399 to your computer and use it in GitHub Desktop.
Google Apps Scriptを使って簡易APIをサクッと作る ref: http://qiita.com/edo_m18/items/0519d241ac7683815a53
function doGet(e) {
return makeContent(makeResponse(e, "GET"));
}
function doPost(e) {
return makeContent ( makeResponse(e,"POST"));
}
function checkId(id) {
var ss = SpreadsheetApp.openById('0ArR-uXirGVyWdFJ1WFZyclpMRzA5dmhnaVMxa29zNlE');
var sheet = ss.getSheetByName('sheet1');
var range = sheet.getRange(1, 1, sheet.getLastRow(), 1);
var values = range.getValues();
var result = false;
values.forEach(function (row) {
row.forEach(function (val) {
if (result) {
return;
}
if (val === id) {
result = true;
return;
}
});
});
return result;
}
function test() {
Logger.log(checkId('abca'));
}
function makeResponse (e, type) {
var valid = checkId(e.parameter.presentCode);
e.parameter.valid = valid;
var s = JSON.stringify({type: type, params: e});
if (!e.parameter.callback) {
return {mime:ContentService.MimeType.JSON, content: s};
}
else {
return {mime: ContentService.MimeType.JAVASCRIPT, content: e.parameter.callback + "(" + s + ");" };
}
}
function makeContent( content) {
return ContentService.createTextOutput(content.content).setMimeType(content.mime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment