forked from perfektio/lambda-sheets-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 817 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const request = require("request");
exports.handler = function(event, context, callback) {
const key = "YOUR-KEY-HERE";
const url = "https://spreadsheets.google.com/feeds/list/"+key+"/od6/public/values?alt=json";
request({
json: true,
url: url
}, function (error, response, body) {
if (error || response.statusCode !== 200) return
let parsed = body.feed.entry.map( (entry) => {
let columns = {
"updated": entry.updated["$t"]
}
// Dynamically add all relevant columns from the Sheets to the response
Object.keys( entry ).forEach( (key) => {
if ( /gsx\$/.test(key) ) {
let newKey = key.replace("gsx$", "");
columns[newKey] = entry[key]["$t"];
}
});
return columns;
})
callback(null, parsed);
});
};