Public/Get-GW2Worlds.ps1
|
<#
.SYNOPSIS Retrieves information about worlds. .DESCRIPTION This function retrieves information about worlds from the Guild Wars 2 API. It supports retrieving specific worlds by ID or all worlds. .PARAMETER Ids The ID(s) of the worlds to retrieve. Can be a single ID, an array of IDs, or "all". .PARAMETER Lang The language to return localized text in. Defaults to "en". Valid values: "en", "es", "de", "fr", "zh". .EXAMPLE Get-GW2Worlds -Ids 1001,1002 Retrieves information for worlds with IDs 1001 and 1002. .EXAMPLE Get-GW2Worlds -Ids "all" Retrieves information for all worlds. .LINK https://wiki.guildwars2.com/wiki/API:2/worlds #> function Get-GW2Worlds { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [object]$Ids, [Parameter(Mandatory = $false)] [ValidateSet("en", "es", "de", "fr", "zh")] [string]$Lang = "en" ) $Uri = "https://api.guildwars2.com/v2/worlds" $QueryParams = @{ lang = $Lang } if ($null -ne $Ids) { if ($Ids -is [array]) { $QueryParams["ids"] = $Ids -join "," } elseif ($Ids -eq "all") { $QueryParams["ids"] = "all" } else { $QueryParams["ids"] = $Ids } } try { Invoke-RestMethod -Uri $Uri -Method Get -Body $QueryParams } catch { Write-Error "Failed to retrieve worlds: $_" } } |