-
Notifications
You must be signed in to change notification settings - Fork 2
/
events.gs
44 lines (38 loc) · 1.52 KB
/
events.gs
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
32
33
34
35
36
37
38
39
40
41
42
43
// The list of calendars I want to fetch information for
const calendarIds = [
'<your calendar ids>',
];
// Arguments used to fetch calendar information. Change as needed. See
// https://developers.google.com/calendar/v3/reference/events/list for more info
const optionalParams = {
showDeleted: false,
singleEvents: true,
orderBy: 'startTime',
};
const doGet = (event = {}) => {
const params = {...optionalParams, ...event.parameter};
const date = new Date();
if (!params.hasOwnProperty('timeMin')) {
params['timeMin'] = (new Date(date.getFullYear(), date.getMonth(), 1)).toISOString();
};
if (!params.hasOwnProperty('timeMax')) {
params['timeMax'] = (new Date(date.getFullYear(), date.getMonth() + 1, 0)).toISOString();
};
const calendarEvents = calendarIds.flatMap(item => Calendar.Events.list(item, params).items);
const formattedEvents = calendarEvents.map(event => {
let start_date = new Date(event.start.dateTime ? event.start.dateTime : event.start.date);
let end_date = new Date(event.start.dateTime ? event.start.dateTime : event.start.date);
return {
'summary': event.summary,
'description': event.description || '',
'start_date': start_date.toDateString(),
'start_date_time': event.start.dateTime || '',
'end_date': end_date.toDateString(),
'end_date_time': event.end.dateTime || '',
'call': event.hangoutLink || '',
};
});
return ContentService.createTextOutput(
JSON.stringify(formattedEvents)
).setMimeType(ContentService.MimeType.JSON);
};