Created
September 4, 2023 11:52
-
-
Save dimitrispaxinos/60ed1c3becd5ff486bab4feb214b3476 to your computer and use it in GitHub Desktop.
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 getData(request) { | |
| let dataSchema = []; | |
| request.fields.forEach(function (field) { | |
| for (const element of schema) { | |
| if (element.name == field.name) { | |
| dataSchema.push(element); | |
| break; | |
| } | |
| } | |
| }); | |
| let countryParam = request.configParams.country; | |
| let url = BASE_URL + (countryParam ? `?country=${encodeURIComponent(countryParam)}` : ''); | |
| let response = UrlFetchApp.fetch(url); | |
| let parsedResponse = JSON.parse(response); | |
| let rows = []; | |
| parsedResponse.forEach(function(university) { | |
| let row = []; | |
| request.fields.forEach(function(field) { | |
| switch (field.name) { | |
| case 'name': | |
| row.push(university.name); | |
| break; | |
| case 'country': | |
| row.push(university.country); | |
| break; | |
| case 'alpha_two_code': | |
| row.push(university.alpha_two_code); | |
| break; | |
| default: | |
| row.push(''); | |
| } | |
| }); | |
| rows.push({ values: row }); | |
| }); | |
| return { | |
| schema: dataSchema, | |
| rows: rows | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment