Last active
January 21, 2018 09:47
-
-
Save nonprofittechy/f62cbfe73e675a20e32d6b30cd75a32c to your computer and use it in GitHub Desktop.
snippet from code.gs - WriteClearly Google Docs Add On
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
/** | |
* 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