Created
January 19, 2014 12:44
-
-
Save edom18/8504399 to your computer and use it in GitHub Desktop.
Google Apps Scriptを使って簡易APIをサクッと作る ref: http://qiita.com/edo_m18/items/0519d241ac7683815a53
This file contains hidden or 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
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