Private/Get-GhostUpdatedAt.ps1
|
function Get-GhostUpdatedAt { <# .SYNOPSIS Returns the current updated_at timestamp of a resource. .DESCRIPTION Ghost only accepts an update that carries the updated_at value the resource has at that moment, which is how it detects that somebody else changed it in the meantime. Functions that update a resource call this when the caller did not pass -UpdatedAt. .EXAMPLE Get-GhostUpdatedAt -Endpoint '/posts/{id}/' -Parameters $PSBoundParameters -Location 'posts' Returns the updated_at value of the post with the id in $PSBoundParameters. #> [CmdletBinding()] [OutputType([object])] param( # The endpoint path of the resource, such as /posts/{id}/. [Parameter(Mandatory)] [string] $Endpoint, # The parameters of the calling function. They provide the values for the tokens in the endpoint. [Parameter(Mandatory)] [System.Collections.IDictionary] $Parameters, # Name of the property that holds the resource in the response, such as posts. [Parameter(Mandatory)] [string] $Location ) $uri = New-URIString -Endpoint $Endpoint -Parameters $Parameters $uri = New-QueryString -Uri $uri -QueryKeys @{ Fields = 'fields' } -Parameters @{ Fields = 'updated_at' } $result = Submit-Request -Uri $uri -Method 'Get' $current = @(Test-ReturnFormat -Result $result -Location $Location)[0] $current.updated_at } |