Skip to content

Instantly share code, notes, and snippets.

@dimitrispaxinos
Created September 4, 2023 11:52
Show Gist options
  • Save dimitrispaxinos/60ed1c3becd5ff486bab4feb214b3476 to your computer and use it in GitHub Desktop.
Save dimitrispaxinos/60ed1c3becd5ff486bab4feb214b3476 to your computer and use it in GitHub Desktop.
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