From 815efb25716d4362aaf132cd1975199f4d77fda5 Mon Sep 17 00:00:00 2001 From: Niraj Nandish Date: Tue, 2 Nov 2021 15:21:40 +0400 Subject: [PATCH] fix: update google spreadsheet api --- .github/workflows/build_and_deploy.yml | 3 ++- src/_services/spreadSheetApi.js | 17 ++++++++--------- src/environment.js | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 3880ee4..0d09143 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -17,7 +17,8 @@ jobs: npm install npm run build env: - REACT_APP_BACKEND_URL: ${{ secrets.REACT_APP_BACKEND_URL }} + REACT_APP_BACKEND_URL: ${{ secrets.REACT_APP_BACKEND_URL }} + REACT_APP_SHEETS_API_KEY: ${{ secrets.REACT_APP_SHEETS_API_KEY }} - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@3.6.2 diff --git a/src/_services/spreadSheetApi.js b/src/_services/spreadSheetApi.js index 4707e67..fcbd7f7 100644 --- a/src/_services/spreadSheetApi.js +++ b/src/_services/spreadSheetApi.js @@ -1,19 +1,18 @@ class SpreadSheetApi { async getWorkSheetData(workSheetId) { - const url = `https://spreadsheets.google.com/feeds/list/${workSheetId}/od6/public/values?alt=json`; + const url = `https://sheets.googleapis.com/v4/spreadsheets/${workSheetId}/values/Sheet1?key=${process.env.REACT_APP_SHEETS_API_KEY}`; const data = await (await fetch(url)).json(); + const keys = data.values.shift(); - return data.feed.entry.map(entry => { - let obj={}; - Object.keys(entry) - .filter(key => key.startsWith('gsx$')) - .forEach(key => { - obj[key.replace('gsx$','')]=entry[key]['$t']; - }) + return data.values.map(entry => { + let obj = {}; + entry.forEach((item, j) => { + obj[keys[j]] = item; + }); return obj; }); } } var instance = new SpreadSheetApi(); -export default instance; \ No newline at end of file +export default instance; diff --git a/src/environment.js b/src/environment.js index c683ea1..7128d09 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,4 +1,4 @@ -export const membersWorkSheetId = '1lGGGhwkitKwHqFijYE8bbMv4WF8d-8-GgqJN1N8JlyI'; -export const eventsWorkSheetId = '13n5gxO8RXD3mSjoa93UnOx_YOaCLAqBFTFjoy256WgY'; +export const membersWorkSheetId = '1GZq0CoE1AiRlOTYj0fAkUFVtvckLjkE4ggVIW1LwHHo'; +export const eventsWorkSheetId = '1GhmmeCZQYMlsJuA8ydMNoNNEloSI4ete9juk89RKXzg'; export const timelineWorkSheetId = '1ccSHjT7jpYFY1mvBzwpAbr9XJwuLKwX51k7eQ3K1PSk'; export const profileImagesRepositoryURL = 'https://raw.githubusercontent.com/WebClub-NITK/Profile-Photos/main/Web%20Club%20Members%20Profile%20Photos/';