Skip to content

Commit

Permalink
GoogleMail.labels (getLabelList function now accepts an optional para…
Browse files Browse the repository at this point in the history
…meter.ids param)

Jobs:GitHub:6889
  • Loading branch information
yannicktrinh committed Jul 2, 2024
1 parent c354da6 commit 2040c81
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
46 changes: 43 additions & 3 deletions Project/Sources/Classes/GoogleMail.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,54 @@ Function update($inMailIds : Collection; $inParameters : Object) : Object
// ----------------------------------------------------


Function getLabelList() : Object
Function getLabelList($inParameters : Object) : Object

Super._clearErrorStack()
var $URL : Text:=Super._getURL()
var $userId : Text:=(Length(String(This.userId))>0) ? This.userId : "me"
$URL+="users/"+$userId+"/labels"

var $response : Object:=Super._sendRequestAndWaitResponse("GET"; $URL)
var $response : Object:=Null
var $labelIds : Collection:=(Value type($inParameters.ids)=Is collection) ? $inParameters.ids : []

If ($labelIds.length=0)

$URL+="users/"+$userId+"/labels"
$response:=Super._sendRequestAndWaitResponse("GET"; $URL)

Else

If (Value type($labelIds[0])=Is object)
$labelIds:=$labelIds.extract("id")
End if

var $i : Integer:=1
var $batchRequestes : Collection:=[]
var $labelId : Text

For each ($labelId; $labelIds)
var $item : Text:="<item"+String($i)+">"
$i+=1
var $urlParams : Text:="users/"+$userId+"/labels/"+$labelId
$batchRequestes.push({request: {verb: "GET"; URL: $URL+$urlParams; id: $item}})
End for each

var $batchParams : Object:={batchRequestes: $batchRequestes; format: "JSON"}
var $batchRequest : cs._GoogleBatchRequest:=cs._GoogleBatchRequest.new(This._getOAuth2Provider(); $batchParams)
var $result:=$batchRequest.sendRequestAndWaitResponse()

If (($result=Null) || ($batchRequest._getLastError()#Null))
var $stack : Collection:=$batchRequest._getErrorStack().reverse()
var $error : Object

For each ($error; $stack)
This._getErrorStack().push($error)
throw($error)
End for each
End if

$response:={labels: $result}

End if

return This._returnStatus($response)

Expand Down
6 changes: 5 additions & 1 deletion Project/Sources/Classes/_GoogleBatchRequest.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ Function sendRequestAndWaitResponse() : Collection

var $result : Variant:=Null
If ($subPart.contentType="application/json")
$result:=This._extractRawMessage(Try(JSON Parse($subPart.content)); This._format; This._mailType)
If (This._format="JSON")
$result:=Try(JSON Parse($subPart.content))
Else
$result:=This._extractRawMessage(Try(JSON Parse($subPart.content)); This._format; This._mailType)
End if
Else
$result:=4D.Blob.new($subPart.content)
End if
Expand Down

0 comments on commit 2040c81

Please sign in to comment.