build-uri.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# The path can be
# * relative to the https://hostname/api/v{next}
# * absolute (eg https://hostname/api/v{next}/objects/{id}/attributes/presentValue)
function buildUri {
    param (
        [Parameter(Mandatory = $true)]
        [string]$siteHost,
        [Parameter(Mandatory = $true)]
        [int]$version,
        [Parameter(Mandatory = $true)]
        [string]$path
    )

    $uri = [Uri]::new($path, [UriKind]::RelativeOrAbsolute)
    if ($uri.IsAbsoluteUri) {
        return $uri
    }

    $fullPath = "https://$siteHost/$([Path]::Join("api", "v" + $version, $path))"
    return [Uri]::new($fullPath)
}