Last active
August 24, 2019 20:25
-
-
Save coelhoadler/6fd4f3d929e077aeea7c3c2faa3915ef to your computer and use it in GitHub Desktop.
Script para integração do Google Spreadsheets junto com o Firebase
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
| //Add in your database secret | |
| var secret = 'UjLXXDC5uGWBmhh4XRvLM4AaeK0igaswEB4Lc4K8' | |
| function getFirebaseUrl(jsonPath) { | |
| /* | |
| We then make a URL builder | |
| This takes in a path, and | |
| returns a URL that updates the data in that path | |
| */ | |
| return ( | |
| 'https://spreed-32349.firebaseio.com/' + | |
| jsonPath + | |
| '.json?auth=' + | |
| secret | |
| ) | |
| } | |
| function syncMasterSheet(excelData) { | |
| var options = { | |
| method: 'put', | |
| contentType: 'application/json', | |
| payload: JSON.stringify(excelData) | |
| } | |
| var fireBaseUrl = getFirebaseUrl('Planilha de Clientes') | |
| UrlFetchApp.fetch(fireBaseUrl, options) | |
| } | |
| function startSync() { | |
| var sheet = SpreadsheetApp.getActiveSheet() | |
| var [rows, columns] = [sheet.getLastRow(), sheet.getLastColumn()] | |
| var data = sheet.getRange(2, 1, rows - 1, columns).getValues() | |
| syncMasterSheet(data) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment