Skip to content

Instantly share code, notes, and snippets.

@nonprofittechy
Last active January 21, 2018 09:47
Show Gist options
  • Save nonprofittechy/f62cbfe73e675a20e32d6b30cd75a32c to your computer and use it in GitHub Desktop.
Save nonprofittechy/f62cbfe73e675a20e32d6b30cd75a32c to your computer and use it in GitHub Desktop.
snippet from code.gs - WriteClearly Google Docs Add On
/**
* Return a single score for the selected text
* @param {string} text text to evaluate, can include HTML elements
* @return {object} object -- has the index (score) and a list of suggestions
*/
function getTextEvaluation() {
var selection = DocumentApp.getActiveDocument().getSelection();
if(selection) {
var textArray = getSelectedText();
} else {
var textArray = getDocumentText();
}
var text = textArray.join('\n');
var url = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
var headers = {
}
var data = {
"json" : 1,
"content" : text
}
var payload = JSON.stringify(data);
var options = {
'method': 'post',
'headers': headers,
'payload': payload
};
var responseRaw = UrlFetchApp.fetch(url, options);
var json = responseRaw.getContentText()
var results = JSON.parse(json);
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment