functions/Get-HipChatRooms.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function Get-HipChatRooms {
<#
 
.SYNOPSIS
    Returns an array of HipChat rooms that the auth token has access to.
.DESCRIPTION
    Returns an array of HipChat rooms that the auth token has access to.
.LINK
    https://github.com/DaveStephens/PSHipchat
.PARAMETER AuthToken
    Required. Your HipChat API token, that you can create here https://www.hipchat.com/account/api
.PARAMETER MaxResults
    The maximum results that you want to see. Defaults to 100, limited to 1000 by the Hipchat API.
.PARAMETER IncludePrivate
    Whether to include private rooms in the results. Defaults to true.
.PARAMETER IncludeArchived
    Whether to include archived rooms in the results. Defaults to false.
.PARAMETER ApiHost
    The URI of the HipChat api (default: api.hipchat.com)
.PARAMETER TimeoutSecs
    Timeout of the HTTP call to the HipChat API. Defaults to 10 seconds.
.EXAMPLE
    Get-HipChatRooms -AuthToken 1234abcd5678efgh -MaxResults 1000
 
#>

    [cmdletbinding()]
        param(
            [Parameter(
                Position = 0,
                Mandatory = $True )]
                [string]$AuthToken,
            [Parameter(
                Position = 1,
                Mandatory = $False )]
                [string]$MaxResults = 100,
            [Parameter(
                Position = 2,
                Mandatory = $False )]
                [string]$IncludePrivate = "true",
            [Parameter(
                Position = 3,
                Mandatory = $False )]
                [string]$IncludeArchived = "false",
            [Parameter(
                Position = 4,
                Mandatory = $False )]
                [string]$ApiHost = "api.hipchat.com",
            [Parameter(
                Position = 5,
                Mandatory = $False )]
                [string]$TimeoutSecs = 10
            )
    begin {
        $DebugPreference = "Continue"
    }

    process    {
        try {
            $url = "https://$ApiHost/v2/room?max-results=$MaxResults&include-archived=$IncludeArchived&include-private=$IncludePrivate"
            Write-Verbose $url

            $headers = @{            
                "Authorization" = "Bearer $AuthToken"
            }
        
            $result = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -TimeoutSec $TimeoutSecs -ContentType 'application/json'
        }
        catch {
            throw $_
        }
    }
    end    {
        return $result.items
    }
}