AzureUrl.ps1
class AzureUrl { hidden [string]$BaseUri hidden [hashtable]$Parameters = [ordered]@{} AzureUrl([string]$BaseUri, [string]$Organization = '', [string]$Project = '') { $this.BaseUri = $BaseUri -ireplace "\{[ ]*organization[ ]*\}", $Organization ` -ireplace "\{[ ]*project[ ]*\}", $Project } AzureUrl([string]$BaseUri, [string]$Organization, [string]$Project, [hashtable]$Parameters) { $this.BaseUri = $BaseUri -ireplace "\{[ ]*organization[ ]*\}", $Organization ` -ireplace "\{[ ]*project[ ]*\}", $Project $this.Parameters += $Parameters } [void] AddParams([hashtable]$Parameters) { $this.Parameters += $Parameters; } [string] ToString() { $QueryParams = @() $this.Parameters.GetEnumerator() | % { if (-not $_.Value) { return } $QueryParams += "{0}={1}" -f $_.Key.ToLower(), $_.Value } if ($QueryParams.Length -gt 0) { $QueryParams = "?" + ($QueryParams -join "&") } else { $QueryParams = '' } return "{0}{1}" -f $this.BaseUri, $QueryParams } } |