Public/Get-GhostTier.ps1
|
function Get-GhostTier { <# .SYNOPSIS Gets tiers from the Ghost site. .DESCRIPTION A tier is what a member subscribes to: the free tier that every site has, and the paid tiers with a price for a month and for a year. Without parameters every tier is returned, archived ones included, ordered by the price for a month. All pages are retrieved unless -Limit or -Page is used, in which case exactly that page is returned. Use -Id to get a single tier. The documentation says that prices and benefits are only returned when they are asked for with -Include. Ghost 6 returns them without it. .EXAMPLE Get-GhostTier Returns every tier of the site. .EXAMPLE Get-GhostTier -Filter 'type:paid+active:true' -Include monthly_price, yearly_price, benefits Returns the paid tiers that are not archived, with their prices and benefits. .EXAMPLE Get-GhostTier -Id '622727ad96a190e914ab6664' Returns one tier. .LINK https://docs.ghost.org/admin-api/tiers/overview #> [CmdletBinding(DefaultParameterSetName = 'Browse')] [OutputType('Ghost.Tier')] param( # Id of the tier to get. [Parameter(Mandatory, ParameterSetName = 'Id', Position = 0, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [string] $Id, # Filter in the Ghost query language (NQL): type:free or type:paid, visibility:public or visibility:none, # active:true or active:false for the archived tiers. [Parameter(ParameterSetName = 'Browse')] [string] $Filter, # Sort order, such as 'name asc'. Without it the tiers are ordered by the price for a month. [Parameter(ParameterSetName = 'Browse')] [string] $Order, # Number of tiers in a page, 100 at most. Returns a single page instead of every tier. [Parameter(ParameterSetName = 'Browse')] [ValidateRange(1, 100)] [int] $Limit, # Number of the page to return. Returns a single page instead of every tier. [Parameter(ParameterSetName = 'Browse')] [ValidateRange(1, [int]::MaxValue)] [int] $Page, # Data to include: monthly_price, yearly_price and benefits. [ValidateSet('monthly_price', 'yearly_price', 'benefits')] [string[]] $Include ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { # Every page is retrieved unless the caller asked for a specific one. $singlePage = $PSBoundParameters.ContainsKey('Limit') -or $PSBoundParameters.ContainsKey('Page') $paginate = $PSCmdlet.ParameterSetName -eq 'Browse' -and -not $singlePage $uri = New-URIString -Endpoint $resources.URI[$PSCmdlet.ParameterSetName] -Parameters $PSBoundParameters $uri = New-QueryString -Uri $uri -QueryKeys $resources.Query -Parameters $PSBoundParameters $result = Submit-Request -Uri $uri -Method $resources.Method -Success $resources.Success -Paginate:$paginate $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |