currently each of the example ps routines handles conversion of arguments into an object separately.
It would make sense to have a single function to handle this - and also maybe handle simple validation (ie making sure required parameters are present). please see below:
function Get-RestPSArguments {
param (
[String] $RequestArgs,
[String] $Body,
[Array] $RequiredParams
)
$RequestObj = New-Object System.Object
if ($RequestArgs) {
Split the Argument Pairs by the '&' character
$ArgumentPairs = $RequestArgs.split('&')
foreach ($ArgumentPair in $ArgumentPairs) {
# Split the Pair data by the '=' character
$Property, $Value = $ArgumentPair.split('=')
$RequestObj | Add-Member -MemberType NoteProperty -Name $Property -value $Value
}
}
if ($RequiredParams) {
$ErrorList=@()
foreach($item in $RequiredParams) {
if (![bool]($RequestObj.PSobject.Properties.name -match $item)) {
$ErrorList += $item
}
}
if ($ErrorList) {
$Errors = [system.String]::Join(",", $ErrorList)
$RequestObj | Add-Member -MemberType NoteProperty -Name "ArgumentsMissing" -Value $Errors
$RequestObj | Add-Member -MemberType NoteProperty -Name "ArgumentsRAW" -Value $RequestArgs
}
}
return $RequestObj
}
--- to call you would do something like
$RequestObj=Get-RestPSArguments -RequestArgs $RequestArgs -RequiredParams @("Name")
if ($RequestObj.ArgumentsMissing) {return $RequestObj.ArgumentsMissing}
currently each of the example ps routines handles conversion of arguments into an object separately. It would make sense to have a single function to handle this - and also maybe handle simple validation (ie making sure required parameters are present). please see below:
function Get-RestPSArguments { param ( [String] $RequestArgs, [String] $Body, [Array] $RequiredParams ) $RequestObj = New-Object System.Object if ($RequestArgs) {
Split the Argument Pairs by the '&' character
}
--- to call you would do something like $RequestObj=Get-RestPSArguments -RequestArgs $RequestArgs -RequiredParams @("Name") if ($RequestObj.ArgumentsMissing) {return $RequestObj.ArgumentsMissing}