Skip to content

Commit

Permalink
Github:11622
Browse files Browse the repository at this point in the history
  • Loading branch information
yannicktrinh committed Dec 16, 2024
1 parent 59d8688 commit 8377a98
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
115 changes: 114 additions & 1 deletion Project/Sources/Classes/GoogleCalendar.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object)


// Mark: - [Public]
// Mark: - Calendars
// ----------------------------------------------------


Expand All @@ -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"})
Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions Project/Sources/Classes/GoogleEventList.4dm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8377a98

Please sign in to comment.