Skip to content

Commit

Permalink
Save google apps script JWT code
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Jul 23, 2024
1 parent ea8c6af commit 8f76173
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions google/appsscript/appsscript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"timeZone": "America/New_York",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.container.ui"
]
}
40 changes: 40 additions & 0 deletions google/appsscript/code.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Lehigh Preserve')
.addItem('Check My Work', 'sendSheetData')
.addToUi();
}

function sendSheetData() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();

var payload = JSON.stringify(data);

var url = 'https://preserve.lehigh.edu/workbench/check';
const oauthToken = ScriptApp.getIdentityToken();
var options = {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + oauthToken
},
contentType: 'application/json',
payload: payload
};

var response = UrlFetchApp.fetch(url, options);
var result = JSON.parse(response.getContentText());

displayErrors(result);
}

function displayErrors(errors) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

for (var cell in errors) {
var error = errors[cell];
sheet.getRange(cell).setBackground('red').setNote(error);
}

SpreadsheetApp.getUi().alert('Errors highlighted in the sheet.');
}

0 comments on commit 8f76173

Please sign in to comment.