Public/New-GhostTier.ps1
|
function New-GhostTier { <# .SYNOPSIS Creates a paid tier on the Ghost site. .DESCRIPTION Creates a tier that members can subscribe to and returns it. A new tier is always active. Ghost derives the slug from the name; it cannot be set. A tier has a currency and a price for a month and for a year. A price is a whole number in the smallest unit of the currency: 500 is 5.00 in dollars or euros. The documentation of Ghost asks for a name only, but Ghost 6 refuses a tier without a currency, so that is required here. Without prices Ghost 6 sets 500 for a month and 5000 for a year. A tier cannot be deleted. Archive one that is no longer offered with Set-GhostTier -Active $false: its members keep their subscription and nobody new can choose it. .EXAMPLE New-GhostTier -Name 'Silver' -MonthlyPrice 500 -YearlyPrice 5000 -Currency usd Creates the tier Silver for 5 dollars a month or 50 dollars a year. .EXAMPLE New-GhostTier -Name 'Gold' -MonthlyPrice 900 -YearlyPrice 9000 -Currency eur -Benefits 'All posts' -TrialDays 7 Creates a tier with a benefit and a free trial of a week. .EXAMPLE New-GhostTier -Name 'Friends' -MonthlyPrice 100 -YearlyPrice 1000 -Currency usd -Visibility none -WhatIf Shows that a tier would be created that is not offered on the site, without creating it. .LINK https://docs.ghost.org/admin-api/tiers/creating-a-tier #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Ghost.Tier')] param( # Name of the tier. [Parameter(Mandatory, Position = 0)] [ValidateNotNullOrEmpty()] [string] $Name, # Price for a month, in the smallest unit of the currency: 500 is 5.00. [ValidateRange(1, [int]::MaxValue)] [int] $MonthlyPrice, # Price for a year, in the smallest unit of the currency: 5000 is 50.00. [ValidateRange(1, [int]::MaxValue)] [int] $YearlyPrice, # Currency of the prices, as its ISO code of three letters, such as usd or eur. [Parameter(Mandatory)] [ValidatePattern('^[A-Za-z]{3}$')] [string] $Currency, # Description of the tier, shown where a member chooses one. [string] $Description, # What a member gets, one line per benefit. [string[]] $Benefits, # Number of days a new member can try the tier for free. 0 is no trial. [ValidateRange(0, [int]::MaxValue)] [int] $TrialDays, # Whether the tier is offered on the site: public, or none for a tier that only you hand out. [ValidateSet('public', 'none')] [string] $Visibility, # Address a member is sent to after subscribing, such as /welcome. [string] $WelcomePageUrl ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { $uri = New-URIString -Endpoint $resources.URI $body = New-BodyString -BodyKeys $resources.Body -Parameters $PSBoundParameters -Wrapper $resources.Result if ($PSCmdlet.ShouldProcess($Name, $resources.Description)) { $result = Submit-Request -Uri $uri -Method $resources.Method -Body $body -Success $resources.Success $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |