Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to Get-SlackUser #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions PSSlack/Public/Get-SlackUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
.Parameter Raw
Return raw output. If specified, Name parameter is ignored

.PARAMETER Paging
If specified, and more data is available when a paging cursor is returned, continue querying Slack until
we have retrieved all the data available.

.PARAMETER MaxQueries
Limit the count of API queries to this number. Only used if you enable -Paging

.EXAMPLE
Get-SlackUser -Token $Token `
-Name ps*
Expand All @@ -45,7 +52,9 @@
[switch]$Presence,
[switch]$Billing,
[switch]$ExcludeBots,
[switch]$Raw
[switch]$Raw,
[switch]$Paging,
[int]$MaxQueries
)
begin
{
Expand All @@ -55,15 +64,35 @@
$body.add('presence', 1)
}

$params = @{
Token = $Token
Method = 'users.list'
}
if($body.keys.count -gt 0)
{
$params.add('body', $Body)
}
$RawUsers = Send-SlackApi @params
$RawUsers = @()
$has_more = $false
$Queries = 0
do {
$params = @{
Token = $Token
Method = 'users.list'
}
if($body.keys.count -gt 0)
{
$params.add('Body', $body)
}
$response = Send-SlackApi @params
$Queries++
if (-not [string]::IsNullOrEmpty($response.response_metadata.next_cursor))
{
$has_more = $true
$body['cursor'] = $response.response_metadata.next_cursor
}
else
{
$has_more = $false
}
$RawUsers += $response
} until (
-not $Paging -or
-not $has_more -or
($MaxQueries -and $Queries -ge $MaxQueries)
)

$HasWildCard = $False
foreach($Item in $Name)
Expand Down