Skip to content

Commit 632919b

Browse files
committed
public-calendars
0 parents  commit 632919b

File tree

7 files changed

+1546
-0
lines changed

7 files changed

+1546
-0
lines changed

Diff for: .gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.yarn/*
2+
!.yarn/patches
3+
!.yarn/plugins
4+
!.yarn/releases
5+
!.yarn/sdks
6+
!.yarn/versions
7+
8+
# Swap the comments on the following lines if you don't wish to use zero-installs
9+
# Documentation here: https://yarnpkg.com/features/zero-installs
10+
.yarn/cache
11+
!.pnp.*
12+
13+
.editorconfig

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# functions

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports["public-calendars"] = require("./public-calendars")

Diff for: package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "functions",
3+
"packageManager": "[email protected]",
4+
"scripts": {
5+
"dev": "functions-framework --target=public-calendars"
6+
},
7+
"dependencies": {
8+
"@google-cloud/functions-framework": "^3.1.3",
9+
"@googleapis/calendar": "^3.0.0"
10+
}
11+
}

Diff for: public-calendars/.index.js.swp

12 KB
Binary file not shown.

Diff for: public-calendars/index.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const functions = require('@google-cloud/functions-framework');
2+
const calendar = require('@googleapis/calendar');
3+
4+
const auth = new calendar.auth.GoogleAuth({
5+
scopes: ['https://www.googleapis.com/auth/calendar.readonly']
6+
});
7+
8+
const getClient = async () => {
9+
const authClient = await auth.getClient();
10+
11+
const client = await calendar.calendar({
12+
version: 'v3',
13+
auth: authClient
14+
});
15+
16+
return client;
17+
}
18+
19+
const getEvents = async (client) => {
20+
21+
return {
22+
"events": await client.events.list({
23+
calendarId: "c_0e61cd901383f3d7ae9ff52f57dceae240a1dac3c9b5e426448b8751bf7f4bce@group.calendar.google.com",
24+
singleEvents: true
25+
}),
26+
"calendar": await client.calendars.get({
27+
calendarId: "c_0e61cd901383f3d7ae9ff52f57dceae240a1dac3c9b5e426448b8751bf7f4bce@group.calendar.google.com",
28+
})
29+
}
30+
}
31+
32+
const handler = (req, res) => {
33+
getClient().then(
34+
client => getEvents(client)
35+
).then(events => {
36+
res.send(events)
37+
}).catch(
38+
e => {
39+
console.error(e);
40+
res.status(500).send("Internal server error. Check the logs")
41+
}
42+
)
43+
44+
}
45+
46+
functions.http('public-calendars', handler);
47+
48+
exports = handler;

0 commit comments

Comments
 (0)