File tree 7 files changed +1546
-0
lines changed
7 files changed +1546
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ # functions
Original file line number Diff line number Diff line change
1
+ exports [ "public-calendars" ] = require ( "./public-calendars" )
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments