Skip to content

Commit

Permalink
GitHub:9479 [Google] User information:
Browse files Browse the repository at this point in the history
- implement Google.user.list with syncToken
- do not throw error when .list() fails
- Misc. fixes
  • Loading branch information
yannicktrinh committed Oct 8, 2024
1 parent 9fb28a1 commit 7c489e6
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 184 deletions.
21 changes: 11 additions & 10 deletions Project/Sources/Classes/GoogleUser.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Function _get($inResourceName : Text; $inPersonFields : Variant) : Object
End if

Case of
: ((Type($inPersonFields)=Is collection) && ($inPersonFields.length>0))
: ((Value type($inPersonFields)=Is collection) && ($inPersonFields.length>0))
$personFields:=$inPersonFields.join(","; ck ignore null or empty)
: ((Value type($inPersonFields)=Is text) && (Length(String($inPersonFields))>0))
$personFields:=$inPersonFields
Expand All @@ -51,9 +51,9 @@ Function _getURLParamsFromObject($inParameters : Object) : Text
var $delimiter : Text:="?"

Case of
: (OB Is defined($inParameters; "select") && (Type($inParameters.select)=Is collection) && ($inParameters.select.length>0))
: ((Value type($inParameters.select)=Is collection) && ($inParameters.select.length>0))
$personFields:=$inParameters.select.join(","; ck ignore null or empty)
: (OB Is defined($inParameters; "select") && (Value type($inParameters.sources)=Is text) && (Length(String($inParameters.select))>0))
: ((Value type($inParameters.select)=Is text) && (Length(String($inParameters.select))>0))
$personFields:=$inParameters.select
Else
$personFields:=This._internals.defaultPersonFields.join(","; ck ignore null or empty)
Expand All @@ -62,19 +62,19 @@ Function _getURLParamsFromObject($inParameters : Object) : Text
$delimiter:="&"

Case of
: (OB Is defined($inParameters; "sources") && (Value type($inParameters.sources)=Is collection) && ($inParameters.sources>0))
: ((Value type($inParameters.sources)=Is collection) && ($inParameters.sources>0))
$sources:=This._internals.defaultSources.join("&sources="; ck ignore null or empty)
: (OB Is defined($inParameters; "sources") && (Value type($inParameters.sources)=Is text) && (Length(String($inParameters.sources))>0))
: ((Value type($inParameters.sources)=Is text) && (Length(String($inParameters.sources))>0))
$sources:=$inParameters.sources
Else
$sources:=This._internals.defaultSources.join("&sources="; ck ignore null or empty)
End case
$urlParams+=($delimiter+"sources="+$sources)

Case of
: (OB Is defined($inParameters; "mergedSources") && (Value type($inParameters.mergedSources)=Is collection) && ($inParameters.mergedSources>0))
: ((Value type($inParameters.mergedSources)=Is collection) && ($inParameters.mergedSources>0))
$urlParams+=($delimiter+"mergeSources="+This._internals.defaultSources.join("&mergeSources="; ck ignore null or empty))
: (OB Is defined($inParameters; "mergedSources") && (Value type($inParameters.mergedSources)=Is text) && (Length(String($inParameters.mergedSources))>0))
: ((Value type($inParameters.mergedSources)=Is text) && (Length(String($inParameters.mergedSources))>0))
$urlParams+=($delimiter+"mergeSources="+$inParameters.mergedSources)
End case

Expand Down Expand Up @@ -121,8 +121,9 @@ Function get($inResourceName : Text; $inPersonFields : Variant) : Object
Function list($inParameters : Object) : Object

Super._clearErrorStack()

var $URL : Text:=Super._getURL()+"people:listDirectoryPeople"+This._getURLParamsFromObject($inParameters)
var $headers : Object:={Accept: "application/json"}

return cs.GoogleUserList.new(This._getOAuth2Provider(); $URL; $headers)
var $requestSyncToken : Boolean:=OB Is defined($inParameters; "requestSyncToken") ? Bool($inParameters.requestSyncToken) : False

return cs.GoogleUserList.new(This._getOAuth2Provider(); $URL; $headers; $requestSyncToken)
4 changes: 2 additions & 2 deletions Project/Sources/Classes/GoogleUserList.4dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Class extends _GoogleBaseList

Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object)
Class constructor($inProvider : cs.OAuth2Provider; $inURL : Text; $inHeaders : Object; $inRequestSyncToken : Boolean)

Super($inProvider; $inURL; "people"; $inHeaders)
Super($inProvider; $inURL; "people"; $inHeaders; $inRequestSyncToken)


// Mark: - [Public]
Expand Down
9 changes: 9 additions & 0 deletions Project/Sources/Classes/Tools.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,12 @@ Function urlEncode($value : Text) : Text
End for

return $result


// ----------------------------------------------------


Function localizedString($inValue : Text) : Text

/* Temp to avoid compilation issues due to command renaming */
return Localized string:C991($inValue)
71 changes: 35 additions & 36 deletions Project/Sources/Classes/_BaseClass.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ property _internals : Object

Class constructor()

This:C1470._internals:={_errorStack: Null:C1517; _throwErrors: True:C214; _savedErrorHandler: ""}
This._internals:={_errorStack: Null; _throwErrors: True; _savedErrorHandler: ""}


// Mark: - [Private]
Expand All @@ -12,21 +12,21 @@ Class constructor()
Function _pushError($inCode : Integer; $inParameters : Object) : Object

// Push error into errorStack without throwing it
var $description : Text:=Localized string:C991("ERR_4DNK_"+String:C10($inCode))
var $description : Text:=cs.Tools.me.localizedString("ERR_4DNK_"+String($inCode))

If (Not:C34(OB Is empty:C1297($inParameters)))
If (Not(OB Is empty($inParameters)))
var $key : Text
For each ($key; $inParameters)
$description:=Replace string:C233($description; "{"+$key+"}"; String:C10($inParameters[$key]))
$description:=Replace string($description; "{"+$key+"}"; String($inParameters[$key]))
End for each
End if

// Push error into errorStack
var $error : Object:={errCode: $inCode; componentSignature: "4DNK"; message: $description}
If (This:C1470._internals._errorStack=Null:C1517)
This:C1470._internals._errorStack:=[]
If (This._internals._errorStack=Null)
This._internals._errorStack:=[]
End if
This:C1470._internals._errorStack.push($error)
This._internals._errorStack.push($error)

return $error

Expand All @@ -37,11 +37,11 @@ Function _pushError($inCode : Integer; $inParameters : Object) : Object
Function _throwError($inCode : Integer; $inParameters : Object)

// Push error into errorStack and throw it
var $error : Object:=This:C1470._pushError($inCode; $inParameters)
var $error : Object:=This._pushError($inCode; $inParameters)

If (This:C1470._internals._throwErrors)
$error.deferred:=True:C214
throw:C1805($error)
If (This._internals._throwErrors)
$error.deferred:=True
throw($error)
End if


Expand All @@ -50,72 +50,72 @@ Function _throwError($inCode : Integer; $inParameters : Object)

Function _try

CLEAR VARIABLE:C89(ERROR)
CLEAR VARIABLE:C89(ERROR METHOD)
CLEAR VARIABLE:C89(ERROR LINE)
CLEAR VARIABLE:C89(ERROR FORMULA)
CLEAR VARIABLE(ERROR)
CLEAR VARIABLE(ERROR METHOD)
CLEAR VARIABLE(ERROR LINE)
CLEAR VARIABLE(ERROR FORMULA)

ON ERR CALL:C155("_catch"; ek errors from components:K92:3)
ON ERR CALL("_catch"; ek errors from components)


// ----------------------------------------------------


Function _finally

ON ERR CALL:C155(This:C1470._internals._throwErrors ? "_throwError" : ""; ek errors from components:K92:3)
ON ERR CALL(This._internals._throwErrors ? "_throwError" : ""; ek errors from components)


// ----------------------------------------------------


Function _getErrorStack : Collection

If (This:C1470._internals._errorStack=Null:C1517)
This:C1470._internals._errorStack:=[]
If (This._internals._errorStack=Null)
This._internals._errorStack:=[]
End if
return This:C1470._internals._errorStack
return This._internals._errorStack


// ----------------------------------------------------


Function _getLastError : Object

If (This:C1470._getErrorStack().length>0)
return This:C1470._getErrorStack().last()
If (This._getErrorStack().length>0)
return This._getErrorStack().last()
End if
return Null:C1517
return Null


// ----------------------------------------------------


Function _getLastErrorCode : Integer

return Num:C11(This:C1470._getLastError().errCode)
return Num(This._getLastError().errCode)


// ----------------------------------------------------


Function _clearErrorStack

This:C1470._getErrorStack().clear()
This._getErrorStack().clear()


// ----------------------------------------------------


Function _throwErrors($inThrowErrors : Boolean)

If (Bool:C1537($inThrowErrors))
This:C1470._internals._throwErrors:=True:C214
This:C1470._resetErrorHandler()
If (Bool($inThrowErrors))
This._internals._throwErrors:=True
This._resetErrorHandler()
Else
This:C1470._installErrorHandler()
This:C1470._internals._throwErrors:=False:C215
This:C1470._getErrorStack().clear()
This._installErrorHandler()
This._internals._throwErrors:=False
This._getErrorStack().clear()
End if


Expand All @@ -124,15 +124,14 @@ Function _throwErrors($inThrowErrors : Boolean)

Function _installErrorHandler($inErrorHandler : Text)

This:C1470._internals._savedErrorHandler:=Method called on error:C704
ON ERR CALL:C155((Length:C16($inErrorHandler)>0) ? $inErrorHandler : "_errorHandler"; ek errors from components:K92:3)
This._internals._savedErrorHandler:=Method called on error
ON ERR CALL((Length($inErrorHandler)>0) ? $inErrorHandler : "_errorHandler"; ek errors from components)


// ----------------------------------------------------


Function _resetErrorHandler

ON ERR CALL:C155(This:C1470._internals._savedErrorHandler; ek errors from components:K92:3)
This:C1470._internals._savedErrorHandler:=""

ON ERR CALL(This._internals._savedErrorHandler; ek errors from components)
This._internals._savedErrorHandler:=""
Loading

0 comments on commit 7c489e6

Please sign in to comment.