Skip to content

Instantly share code, notes, and snippets.

@torgro
Created February 17, 2018 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgro/3e123e796862399ef924a265c6a818e4 to your computer and use it in GitHub Desktop.
Save torgro/3e123e796862399ef924a265c6a818e4 to your computer and use it in GitHub Desktop.
function Set-FileApi
{
[cmdletbinding(
SupportsShouldProcess
)]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$FileName
,
[string]
$Content = [string]::Empty
)
$invokeSplat = @{
Uri = "http://localhost:11000/api/file"
Method = "Post"
}
$body = @{
Authorization = $Authorization.Authorization
FileName = $FileName
Content = $Content
}
if ($PSCmdlet.ShouldProcess($FileName, "Set content"))
{
$respons = Invoke-RestMethod @invokeSplat -Body $body
if ($respons.error)
{
throw $respons.error.message
}
if ($respons.StatusCode -eq 200)
{
$respons.Content | ConvertFrom-Json
}
else
{
Write-Error -Message "Respons was not successfull, StatusCode is [$($respons.StatusCode)]" -ErrorAction Stop
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment