Public/Get-DunePackage.ps1
|
function Get-DunePackage { [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(Position = 0)] [string]$Name, [Parameter(ParameterSetName = "Id")] [guid]$Id, [Parameter(ParameterSetName = "Resource", ValueFromPipeline)] [DuneResource]$Resource, [Parameter()] [string]$DisplayName, [Parameter()] [string]$Version, [Parameter()] [string]$Vendor, [Parameter()] [switch]$Raw ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $ProcessedUrls = @() $BaseUri = "resourceaddons/packages" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" # Build Uri $Uri = switch ($PSCmdlet.ParameterSetName) { 'Id' { '{0}?Id={1}' -f $BaseUri, $Id } 'Resource' { '{0}?ResourceId={1}' -f $BaseUri, $Resource.Id } Default { $BaseUri } } if ($Name) { $Uri = $Uri | Add-UriQueryParam "NameILike=$Name" -ConvertWildcards } if ($DisplayName) { $Uri = $Uri | Add-UriQueryParam "DisplayNameILike=$DisplayName" -ConvertWildcards } if ($Version) { $Uri = $Uri | Add-UriQueryParam "VersionLike=$Version" -ConvertWildcards } if ($Vendor) { $Uri = $Uri | Add-UriQueryParam "VendorILike=$Vendor" -ConvertWildcards } # ApiCall Cache if ($ProcessedUrls -notcontains $Uri) { try { # ApiCall and Object conversion $ResultItems = Invoke-DuneApiRequest -Uri $Uri -Method $Method -ExtractItems $ProcessedUrls += $Uri $ReturnObjects += $ResultItems | ForEach-Object { if ($Raw) { $_ } else { ConvertTo-DuneClassObject -Class DunePackage -InputObject $_ } } } catch { throw $_ } } else { Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked" } } end { Write-Debug "$($MyInvocation.MyCommand)|end" return $ReturnObjects } } |