From f3619a8578914e285c1c58eed5bbdf9b5afc51fa Mon Sep 17 00:00:00 2001 From: Zoltan Polgar Date: Fri, 19 Jul 2024 22:38:41 +0200 Subject: [PATCH] Implement FUND_LOOKUP sheet function --- sheets-extension/Code.gs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/sheets-extension/Code.gs b/sheets-extension/Code.gs index 47af8fa..a4d87b9 100644 --- a/sheets-extension/Code.gs +++ b/sheets-extension/Code.gs @@ -32,11 +32,37 @@ function FUND_RATE_LOOKUP(isin, attribute = 'rate', startDate = null, endDate = } return [date, value]; }); - - Logger.log(reducedData); return reducedData; } -function FUND_LOOKUP(attribute = 'name', value = null) { +function FUND_LOOKUP(manager = null, type = null, category = null, currency = null) { + var apiUrl = `${BASE_API_URL}/sheets/funds`; + var dataToPost = {}; + + if (manager) { + dataToPost.manager = manager; + } + if (type) { + dataToPost.type = type; + } + if (category) { + dataToPost.category = category; + } + if (currency) { + dataToPost.currency = currency; + } + var options = { + 'method': 'post', + 'contentType': 'application/json', + 'payload': JSON.stringify(dataToPost) + }; + var response = UrlFetchApp.fetch(apiUrl, options); + + var responseData = JSON.parse(response.getContentText()); + + var reducedData = responseData.map(function(item) { + return [item['isin'], item['manager'], item['type'], item['category'], item['currency']]; + }); + return reducedData; } \ No newline at end of file