From 8740c980a149e5e96ef5b89f200b4198f22923d6 Mon Sep 17 00:00:00 2001 From: Yannick Trinh Date: Mon, 6 Jan 2025 22:36:43 +0100 Subject: [PATCH 1/2] Github:11622 (refactoring) --- Project/Sources/Classes/GoogleCalendar.4dm | 16 +++++++++----- .../Sources/Classes/GoogleCalendarList.4dm | 4 ++-- Project/Sources/Classes/GoogleEventList.4dm | 4 ++-- Project/Sources/Classes/GoogleMailIdList.4dm | 2 +- Project/Sources/Classes/GoogleUserList.4dm | 2 +- Project/Sources/Classes/_GoogleBaseList.4dm | 22 ++++++++++--------- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Project/Sources/Classes/GoogleCalendar.4dm b/Project/Sources/Classes/GoogleCalendar.4dm index 6d5d293..2c4482b 100644 --- a/Project/Sources/Classes/GoogleCalendar.4dm +++ b/Project/Sources/Classes/GoogleCalendar.4dm @@ -76,8 +76,11 @@ Function getCalendars($inParameters : Object) : Object $delimiter:="&" End if - var $URL : Text:=This._getURL()+$urlParams - var $result : cs.GoogleCalendarList:=cs.GoogleCalendarList.new(This._getOAuth2Provider(); $URL; $headers) + var $options : Object:={} + $options.url:=This._getURL()+$urlParams + $options.headers:={Accept: "application/json"} + + var $result : cs.GoogleCalendarList:=cs.GoogleCalendarList.new(This._getOAuth2Provider(); $options) Super._throwErrors(True) @@ -205,7 +208,6 @@ Function getEvents($inParameters : Object) : Object Super._clearErrorStack() Super._throwErrors(False) - var $headers : Object:={Accept: "application/json"} var $calendarId : Text:=(Length(String($inParameters.calendarId))>0) ? $inParameters.calendarId : "primary" var $urlParams : Text:="calendars/"+cs.Tools.me.urlEncode($calendarID)+"/events" var $delimiter : Text:="?" @@ -275,10 +277,12 @@ Function getEvents($inParameters : Object) : Object End if $urlParams+=($delimiter+"timeZone="+String($timeZone)) - var $URL : Text:=This._getURL()+$urlParams + var $options : Object:={} + $options.url:=This._getURL()+$urlParams + $options.headers:={Accept: "application/json"} + $options.attributes:=["kind"; "etag"; "summary"; "calendarId"; "description"; "updated"; "timeZone"; "accessRole"; "defaultReminders"] - var $additionalAttributes : Collection:=["kind"; "etag"; "summary"; "calendarId"; "description"; "updated"; "timeZone"; "accessRole"; "defaultReminders"] - var $result : cs.GoogleEventList:=cs.GoogleEventList.new(This._getOAuth2Provider(); $URL; $headers; $additionalAttributes) + var $result : cs.GoogleEventList:=cs.GoogleEventList.new(This._getOAuth2Provider(); $options) If ((Value type($result.calendarId)=Is undefined) && (Value type($inParameters.calendarId)=Is text) && (Length(String($inParameters.calendarId))>0)) $result.calendarId:=$inParameters.calendarId diff --git a/Project/Sources/Classes/GoogleCalendarList.4dm b/Project/Sources/Classes/GoogleCalendarList.4dm index e5e920b..3d3ebea 100644 --- a/Project/Sources/Classes/GoogleCalendarList.4dm +++ b/Project/Sources/Classes/GoogleCalendarList.4dm @@ -1,8 +1,8 @@ Class extends _GoogleBaseList -Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object) +Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object) - Super($inProvider; $inURL; "items"; $inHeaders) + Super($inProvider; $inParameters) // Mark: - [Public] diff --git a/Project/Sources/Classes/GoogleEventList.4dm b/Project/Sources/Classes/GoogleEventList.4dm index 758039a..6c84f77 100644 --- a/Project/Sources/Classes/GoogleEventList.4dm +++ b/Project/Sources/Classes/GoogleEventList.4dm @@ -10,9 +10,9 @@ property timeZone : Text property accessRole : Text property defaultReminders : Collection -Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object; $inAdditionalAttributes : Collection) +Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object) - Super($inProvider; $inURL; "items"; $inHeaders; $inAdditionalAttributes) + Super($inProvider; $inParameters) // Mark: - [Public] diff --git a/Project/Sources/Classes/GoogleMailIdList.4dm b/Project/Sources/Classes/GoogleMailIdList.4dm index 45e77c2..f729f75 100644 --- a/Project/Sources/Classes/GoogleMailIdList.4dm +++ b/Project/Sources/Classes/GoogleMailIdList.4dm @@ -2,7 +2,7 @@ Class extends _GoogleBaseList Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text) - Super($inProvider; $inURL; "messages") + Super($inProvider; {url: $inURL; elements: "messages"}) This._internals._URL:=$inURL diff --git a/Project/Sources/Classes/GoogleUserList.4dm b/Project/Sources/Classes/GoogleUserList.4dm index 2a2751b..5e9bcf5 100644 --- a/Project/Sources/Classes/GoogleUserList.4dm +++ b/Project/Sources/Classes/GoogleUserList.4dm @@ -2,7 +2,7 @@ Class extends _GoogleBaseList Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object) - Super($inProvider; $inURL; "people"; $inHeaders) + Super($inProvider; {url: $inURL; elements: "people"; headers: $inHeaders}) // Mark: - [Public] diff --git a/Project/Sources/Classes/_GoogleBaseList.4dm b/Project/Sources/Classes/_GoogleBaseList.4dm index 1bc7d2e..3a9abb2 100644 --- a/Project/Sources/Classes/_GoogleBaseList.4dm +++ b/Project/Sources/Classes/_GoogleBaseList.4dm @@ -6,14 +6,16 @@ property statusText : Text property success : Boolean property errors : Collection -Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inResultListName : Text; $inHeaders : Object; $inAdditionalAttributes : Collection) +Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object) Super($inProvider) - - This._internals._URL:=$inURL - This._internals._headers:=$inHeaders - This._internals._attribute:=$inResultListName - This._internals._additionalAttributes:=$inAdditionalAttributes + + If ((Value type($inParameters.url)=Is text) && (Length($inParameters.url)>0)) + This._internals._URL:=$inParameters.url + End if + This._internals._headers:=(Value type($inParameters.headers)=Is object) ? $inParameters.headers : Null + This._internals._elements:=(Value type($inParameters.elements)=Is text) ? $inParameters.elements : "items" + This._internals._attributes:=(Value type($inParameters.attributes)=Is collection) ? $inParameters.attributes : Null This._internals._nextPageToken:="" This._internals._history:=[] This._internals._throwErrors:=False @@ -50,13 +52,13 @@ Function _getList($inPageToken : Text) : Boolean If ($response#Null) - If (OB Is defined($response; This._internals._attribute)) - This._internals._list:=OB Get($response; This._internals._attribute; Is collection) + If (OB Is defined($response; This._internals._elements)) + This._internals._list:=OB Get($response; This._internals._elements; Is collection) End if - If (This._internals._additionalAttributes#Null) + If (This._internals._attributes#Null) var $key : Text - For each ($key; This._internals._additionalAttributes) + For each ($key; This._internals._attributes) If (OB Is defined($response; $key)) This[$key]:=OB Get($response; $key) From 3c497970bfe6e75a906212593e7f406185669e64 Mon Sep 17 00:00:00 2001 From: Yannick Trinh Date: Tue, 7 Jan 2025 11:10:15 +0100 Subject: [PATCH 2/2] Github:11622 (refactoring) --- Project/Sources/Classes/_GoogleBaseList.4dm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Project/Sources/Classes/_GoogleBaseList.4dm b/Project/Sources/Classes/_GoogleBaseList.4dm index 3a9abb2..f7e3062 100644 --- a/Project/Sources/Classes/_GoogleBaseList.4dm +++ b/Project/Sources/Classes/_GoogleBaseList.4dm @@ -9,12 +9,12 @@ property errors : Collection Class constructor($inProvider : cs.OAuth2Provider; $inParameters : Object) Super($inProvider) - + If ((Value type($inParameters.url)=Is text) && (Length($inParameters.url)>0)) This._internals._URL:=$inParameters.url End if This._internals._headers:=(Value type($inParameters.headers)=Is object) ? $inParameters.headers : Null - This._internals._elements:=(Value type($inParameters.elements)=Is text) ? $inParameters.elements : "items" + This._internals._elements:=((Value type($inParameters.elements)=Is text) && (Length($inParameters.elements)>0)) ? $inParameters.elements : "items" This._internals._attributes:=(Value type($inParameters.attributes)=Is collection) ? $inParameters.attributes : Null This._internals._nextPageToken:="" This._internals._history:=[] @@ -57,11 +57,11 @@ Function _getList($inPageToken : Text) : Boolean End if If (This._internals._attributes#Null) - var $key : Text - For each ($key; This._internals._attributes) + var $attribute : Text + For each ($attribute; This._internals._attributes) - If (OB Is defined($response; $key)) - This[$key]:=OB Get($response; $key) + If (OB Is defined($response; $attribute)) + This[$attribute]:=OB Get($response; $attribute) End if End for each End if