From 8377a987f57749ced0776e25c7eb33593ba9e40c Mon Sep 17 00:00:00 2001 From: Yannick Trinh Date: Mon, 16 Dec 2024 15:46:19 +0100 Subject: [PATCH] Github:11622 --- Project/Sources/Classes/GoogleCalendar.4dm | 115 +++++++++++++++++++- Project/Sources/Classes/GoogleEventList.4dm | 14 +++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 Project/Sources/Classes/GoogleEventList.4dm diff --git a/Project/Sources/Classes/GoogleCalendar.4dm b/Project/Sources/Classes/GoogleCalendar.4dm index 5ad373d..6a899aa 100644 --- a/Project/Sources/Classes/GoogleCalendar.4dm +++ b/Project/Sources/Classes/GoogleCalendar.4dm @@ -14,6 +14,7 @@ Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object) // Mark: - [Public] + // Mark: - Calendars // ---------------------------------------------------- @@ -22,7 +23,7 @@ Function getCalendar($inID : Text) : Object // GET https://www.googleapis.com/calendar/v3/users/me/calendarList/calendarId var $response : Variant:=Null - + Case of : (Type($inID)#Is text) Super._throwError(10; {which: "\"calendarId\""; function: "google.calendar.getCalendar"}) @@ -81,3 +82,115 @@ Function getCalendars($inParameters : Object) : Object Super._throwErrors(True) return $result + + + // Mark: - [Public] + // Mark: - Calendars + // ---------------------------------------------------- + + +Function getEvent($inParameters : Object) : Object + + // GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId + + var $response : Variant:=Null + + Case of + : (Type($inParameters.eventId)#Is text) + Super._throwError(10; {which: "\"eventId\""; function: "google.calendar.getEvent"}) + + Else + + var $eventId : Text:=(Length(String($inParameters.eventId))>0) ? $inParameters.eventId : "primary" + var $calendarId : Text:=(Length(String($inParameters.calendarId))>0) ? $inParameters.calendarId : "primary" + var $URL : Text:=Super._getURL()+"calendar/v3/calendars/"+cs.Tools.me.urlEncode($calendarID)+"/events/"+cs.Tools.me.urlEncode($eventId) + var $headers : Object:={Accept: "application/json"} + $response:=Super._sendRequestAndWaitResponse("GET"; $URL; $headers) + + End case + + return $response + + + // ---------------------------------------------------- + + +Function getEvents($inParameters : Object) : Object + + // GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events + Super._clearErrorStack() + Super._throwErrors(False) + + var $response : Object:=Null + var $headers : Object:={Accept: "application/json"} + var $calendarId : Text:=(Length(String($inParameters.calendarId))>0) ? $inParameters.calendarId : "primary" + var $urlParams : Text:="calendar/v3/calendars/"+cs.Tools.me.urlEncode($calendarID)+"/events" + var $delimiter : Text:="?" + + If ((Value type($inParameters.eventTypes)=Is text) && (Length(String($inParameters.eventTypes))>0)) + $urlParams+=($delimiter+"eventTypes="+$inParameters.eventTypes) + $delimiter:="&" + End if + If ((Value type($inParameters.iCalUID)=Is text) && (Length(String($inParameters.iCalUID))>0)) + $urlParams+=($delimiter+"iCalUID="+String($inParameters.iCalUID)) + $delimiter:="&" + End if + If (Not(Value type($inParameters.maxAttendees)=Is undefined)) + $urlParams+=($delimiter+"maxAttendees="+Choose(Value type($inParameters.maxAttendees)=Is text; $inParameters.maxAttendees; String($inParameters.maxAttendees))) + $delimiter:="&" + End if + If (Not(Value type($inParameters.maxResults)=Is undefined)) + $urlParams+=($delimiter+"maxResults="+Choose(Value type($inParameters.maxResults)=Is text; $inParameters.maxResults; String($inParameters.maxResults))) + $delimiter:="&" + End if + If ((Value type($inParameters.orderBy)=Is text) && (Length(String($inParameters.orderBy))>0)) + $urlParams+=($delimiter+"orderBy="+String($inParameters.orderBy)) + $delimiter:="&" + End if + If ((Value type($inParameters.search)=Is text) && (Length(String($inParameters.search))>0)) + $urlParams+=($delimiter+"search="+String($inParameters.search)) + $delimiter:="&" + End if + If (Not(Value type($inParameters.showDeleted)=Is undefined)) + $urlParams+=($delimiter+"showDeleted="+Choose(Bool($inParameters.showDeleted); "true"; "false")) + $delimiter:="&" + End if + If (Not(Value type($inParameters.showHiddenInvitations)=Is undefined)) + $urlParams+=($delimiter+"showHiddenInvitations="+Choose(Bool($inParameters.showHiddenInvitations); "true"; "false")) + $delimiter:="&" + End if + If (Not(Value type($inParameters.singleEvents)=Is undefined)) + $urlParams+=($delimiter+"singleEvents="+Choose(Bool($inParameters.singleEvents); "true"; "false")) + $delimiter:="&" + End if + If ((Value type($inParameters.startDateTime)=Is text) && (Length(String($inParameters.startDateTime))>0)) + $urlParams+=($delimiter+"startDateTime="+String($inParameters.startDateTime)) + $delimiter:="&" + End if + If ((Value type($inParameters.endDateTime)=Is text) && (Length(String($inParameters.endDateTime))>0)) + $urlParams+=($delimiter+"endDateTime="+String($inParameters.endDateTime)) + $delimiter:="&" + End if + If ((Value type($inParameters.timeZone)=Is text) && (Length(String($inParameters.timeZone))>0)) + $urlParams+=($delimiter+"timeZone="+String($inParameters.timeZone)) + $delimiter:="&" + End if + If ((Value type($inParameters.updatedMin)=Is text) && (Length(String($inParameters.updatedMin))>0)) + $urlParams+=($delimiter+"updatedMin="+String($inParameters.updatedMin)) + $delimiter:="&" + End if + If ((Value type($inParameters.privateExtendedProperty)=Is text) && (Length(String($inParameters.privateExtendedProperty))>0)) + $urlParams+=($delimiter+"privateExtendedProperty="+String($inParameters.privateExtendedProperty)) + $delimiter:="&" + End if + If ((Value type($inParameters.sharedExtendedProperty)=Is text) && (Length(String($inParameters.sharedExtendedProperty))>0)) + $urlParams+=($delimiter+"sharedExtendedProperty="+String($inParameters.sharedExtendedProperty)) + $delimiter:="&" + End if + + var $URL : Text:=This._getURL()+$urlParams + var $result : cs.GoogleEventList:=cs.GoogleEventList.new(This._getOAuth2Provider(); $URL; $headers) + + Super._throwErrors(False) + + return $response diff --git a/Project/Sources/Classes/GoogleEventList.4dm b/Project/Sources/Classes/GoogleEventList.4dm new file mode 100644 index 0000000..6717e05 --- /dev/null +++ b/Project/Sources/Classes/GoogleEventList.4dm @@ -0,0 +1,14 @@ +Class extends _GoogleBaseList + +Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object) + + Super($inProvider; $inURL; "items"; $inHeaders) + + + // Mark: - [Public] + // ---------------------------------------------------- + + +Function get events() : Collection + + return This._internals._list