-
-
Save techstreams/92cf9bdbef3f4e97af15 to your computer and use it in GitHub Desktop.
Simple Google Apps Script TextExpander Snippet Server for iOS Workflow App. See blog post - https://goo.gl/ZQiPel
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
/** | |
* Copyright (c), Laura Taylor. (MIT Licensed) | |
* https://github.com/techstreams | |
*/ | |
/** | |
* Simple Google Apps Script Content Server | |
* @returns {String} | |
*/ | |
function doGet(e) { | |
// Change ssId to reflect correct spreadsheet ID. | |
// Use getSSId() convenient method to get spreadsheet ID. | |
var ssId = '<replace with spreadsheet id>'; | |
var groups, json, sheets, s, ss; | |
json = new Object(); | |
json.code = 200; | |
try { | |
ss = SpreadsheetApp.openById(ssId); | |
// If there is a snippet group name parameter, get the snippets from the corresponding sheet and create a JSON response. | |
// Otherwise, return a comma separated list of sheet names. | |
if (e.parameter.name) { | |
sheets = ss.getSheetByName(e.parameter.name.trim()); | |
if (sheets) { | |
json.snippets = []; | |
sheets.getDataRange().getValues().forEach(function(row) { | |
s = new Object(); | |
s['abbrv'] = row[0]; | |
s['snip'] = row[1]; | |
json.snippets.push(s); | |
}) | |
} else { | |
throw new Error(); // No sheet found | |
} | |
} else { | |
sheets = ss.getSheets(); | |
groups = []; | |
sheets.forEach(function(sheet) { | |
groups.push(sheet.getName()); | |
}); | |
json.snippetgroups = groups.join(','); | |
} | |
} catch(err) { | |
json.code = 500; // Return an error code if error detected | |
} | |
return ContentService.createTextOutput(JSON.stringify(json)); // Return response to Workflow | |
} | |
/** | |
* Convenience method to retrieve current spreadsheet Id for configuration/setup in doGet() method. | |
* Will open an Alert pop-up in the spreadsheet. Execute from the script editor run menu. | |
* @returns {Object} | |
*/ | |
function getSSId() { | |
Browser.msgBox(SpreadsheetApp.getActive().getId()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment