Skip to content

Commit

Permalink
Adding Block List Functions (#110)
Browse files Browse the repository at this point in the history
* Adding BlockList management cmdlets

* refind behavior of blocklist cmdlets

* Uncommented section used for testing

---------

Co-authored-by: Andrew Hoggins <andyhoggins@me.com>
  • Loading branch information
andrew-hoggins and Andrew Hoggins authored May 6, 2024
1 parent aad13c6 commit 55af03b
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 0 deletions.
93 changes: 93 additions & 0 deletions PSZoom/Public/Phone/BlockList/Get-ZoomPhoneBlockList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<#
.SYNOPSIS
List Block Lists on a Zoom account.
.DESCRIPTION
List Block Lists on a Zoom account.
.PARAMETER BlockedLisIId
Unique Identifier of the Block Lists.
.PARAMETER PageSize
The number of records returned within a single API call (Min 30 - MAX 100).
.PARAMETER NextPageToken
The next page token is used to paginate through large result sets. A next page token will be returned whenever the set
of available results exceeds the current page size. The expiration period for this token is 15 minutes.
.PARAMETER Full
When using -Full switch, receive the full JSON Response to see the next_page_token.
.LINK
https://developers.zoom.us/docs/api/rest/reference/phone/methods/#operation/listBlockedList
.EXAMPLE
Return a list of all the Block Lists.
Get-ZoomPhoneBlockList
.EXAMPLE
Return the first page of Block Lists
Get-ZoomPhoneBlockList -BlockedLisIId "3vt4b7wtb79q4wvb"
.EXAMPLE
Get a page of Block Lists
Get-ZoomPhoneBlockList -PageSize 100 -NextPageToken "8w7vt487wqtb457qwt4"
#>

function Get-ZoomPhoneBlockList {
[CmdletBinding(DefaultParameterSetName="AllData")]
[Alias("Get-ZoomPhoneBlockLists")]
param (
[Parameter(
ParameterSetName="SelectedRecord",
Mandatory = $True,
Position = 0,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True
)]
[Alias('id', 'BlockedLisIIds')]
[string[]]$BlockedLisIId,

[parameter(ParameterSetName="NextRecords")]
[ValidateRange(1, 100)]
[Alias('page_size')]
[int]$PageSize = 100,

# The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
[parameter(ParameterSetName="NextRecords")]
[Alias('next_page_token')]
[string]$NextPageToken,

[parameter(ParameterSetName="SpecificSite")]
[parameter(ParameterSetName="AllData")]
[switch]$Full = $False
)

process {
$baseURI = "https://api.$ZoomURI/v2/phone/blocked_list"

switch ($PSCmdlet.ParameterSetName) {
"NextRecords" {
$AggregatedResponse = Get-ZoomPaginatedData -URI $baseURI -PageSize $PageSize -NextPageToken $NextPageToken
}

"SelectedRecord" {
$AggregatedResponse = Get-ZoomPaginatedData -URI $baseURI -ObjectId $BlockedLisIId
}

"AllData" {
$AggregatedResponse = Get-ZoomPaginatedData -URI $baseURI -PageSize 100
}
}

if ($Full) {
# No additional data with full so switching to normal query
$AggregatedIDs = $AggregatedResponse | select-object -ExpandProperty ID
$AggregatedResponse = Get-ZoomItemFullDetails -ObjectIds $AggregatedIDs -CmdletToRun $MyInvocation.MyCommand.Name
}

Write-Output $AggregatedResponse
}
}
170 changes: 170 additions & 0 deletions PSZoom/Public/Phone/BlockList/New-ZoomPhoneBlockList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<#
.SYNOPSIS
Create a Block List.
.PARAMETER BlockType
State whether you want the block type to be inbound or outbound.
inbound: Pass this value to prevent the blocked number or prefix from calling into the phone users.
outbound: Pass this value to prevent phone users from calling the blocked number or prefix.
Allowed: inbound┃outbound┃threat
.PARAMETER Comment
Provide a comment to help you identify the blocked number or prefix
.PARAMETER Country
The country information. For example, entering US or CH.
Must be two character country code.
.PARAMETER MatchType
Specify the match type for the blocked list:
phoneNumber: Choose this option (Phone Number Match) if you want to block a specific phone number. Provide the phone number in the phone_number field and the country code in the country field.
prefix: Choose this option (Prefix Match) if you want to block all numbers with a specific country or an area code. Enter a phone number in the phone_number field and in the country field, enter a country code as part of the prefix.
Allowed: phoneNumber┃prefix
.PARAMETER PhoneNumber
The phone number to be blocked if you passed phoneNumber as the value for the match_type field. If you passed prefix as the value for the match_type field, provide the prefix of the phone number in the country field.
.PARAMETER Status
Enable or disable the blocking. One of the following values are allowed:
active: Keep the blocking active.
inactive: Disable the blocking.
Allowed: active┃inactive
.OUTPUTS
Outputs object
.EXAMPLE
Create inbound block list for single number
New-ZoomPhoneBlockList -BlockType "inbound" -Comment "Confirmed Spam Caller" -MatchType "phoneNumber" -PhoneNumber "+19876543210" -Status "active"
.EXAMPLE
Create outbound block list for a prefix
New-ZoomPhoneBlockList -BlockType "outbound" -Comment "Some Random Island" -Country "Kiwis" -MatchType "prefix" -PhoneNumber "+64" -Status "active"
.LINK
https://developers.zoom.us/docs/api/rest/reference/phone/methods/#operation/addBlockList
#>

function New-ZoomPhoneBlockList {
[CmdletBinding(
SupportsShouldProcess = $True
)]
Param(
[Parameter(
Mandatory = $True,
Position = 1
)]
[ValidateSet("inbound","outbound")]
[string]$BlockType,

[Parameter(
Mandatory = $True,
Position = 2
)]
[string]$Comment,

[Parameter(
Mandatory = $True,
Position = 4
)]
[ValidateLength(2, 2)]
[string]$Country,

[Parameter(
Mandatory = $True,
Position = 3
)]
[ValidateSet("phoneNumber","prefix")]
[string]$MatchType,

[Parameter(
Mandatory = $True,
Position = 5
)]
[string]$PhoneNumber,

[Parameter(
Mandatory = $True,
Position = 6
)]
[ValidateSet("active","inactive")]
[string]$Status,


[switch]$PassThru

)

begin {

# Fixing case sensitivity on parameters as call will fail without it
if ($PSBoundParameters.ContainsKey('BlockType')) {
$BlockType = $BlockType.ToLower()
}
if ($PSBoundParameters.ContainsKey('Status')) {
$Status = $Status.ToLower()
}
if ($PSBoundParameters.ContainsKey('MatchType')) {
$Status = $Status.ToLower()

if ($MatchType -eq "phonenumber"){

$MatchType = "phoneNumber"
}elseif ($MatchType -eq "prefix") {

$MatchType = $MatchType.ToLower()
}
}

$Request = [System.UriBuilder]"https://api.$ZoomURI/v2/phone/blocked_list"

#region body
$RequestBody = @{ }

$KeyValuePairs = @{
'block_type' = $BlockType
'comment' = $Comment
'country' = $Country
'match_type' = $MatchType
'phone_number' = $PhoneNumber
'status' = $Status
}

$KeyValuePairs.Keys | ForEach-Object {
if (-not (([string]::IsNullOrEmpty($KeyValuePairs.$_)) -or ($KeyValuePairs.$_ -eq 0) )) {
$RequestBody.Add($_, $KeyValuePairs.$_)
}
}
#endregion body

$RequestBody = $RequestBody | ConvertTo-Json -Depth 10

}
process {

$Message =
@"
Method: POST
URI: $($Request | Select-Object -ExpandProperty URI | Select-Object -ExpandProperty AbsoluteUri)
Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $Name, "Create Block List")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method POST

if (-not $PassThru) {
Write-Output $response
}
}
}
}
67 changes: 67 additions & 0 deletions PSZoom/Public/Phone/BlockList/Remove-ZoomPhoneBlockList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<#
.SYNOPSIS
Remove a Blocked List.
.PARAMETER BlockedListId
Remove a Blocked List.
.OUTPUTS
No output. Can use Passthru switch to pass BlockedListId to output.
.EXAMPLE
Remove-ZoomPhoneBlockList -BlockedListId "se5d7r6fcvtbyinj"
.LINK
https://developers.zoom.us/docs/api/rest/reference/phone/methods/#operation/deleteABlockedList
#>

function Remove-ZoomPhoneBlockList {
[CmdletBinding(SupportsShouldProcess = $True)]
Param(
[Parameter(
Mandatory = $True,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True,
Position = 0
)]
[ValidateLength(1, 128)]
[Alias('Id','Ids','BlockedListIds')]
[string[]]$BlockedListId,

[switch]$PassThru
)



process {
foreach ($BlockedList in $BlockedListId) {

$Request = [System.UriBuilder]"https://api.$ZoomURI/v2/phone/blocked_list/$BlockedList"

$Message =
@"
Method: DELETE
URI: $($Request | Select-Object -ExpandProperty URI | Select-Object -ExpandProperty AbsoluteUri)
Body:
$RequestBody
"@



if ($pscmdlet.ShouldProcess($Message, $BlockedList, "Delete")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method Delete

if (-not $PassThru) {
Write-Output $response
}
}
}

if ($PassThru) {
Write-Output $BlockedListId
}
}
}
Loading

0 comments on commit 55af03b

Please sign in to comment.