Public/New-ObservationScalars.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
    .SYNOPSIS
    Creates an object that contains the observation and all the scalars

    .DESCRIPTION
    Creates the message body in hashtable form to send to the eCC Salesforce API to accept measurements

    .INPUTS
    None. You cannot pipe objects to New-ObservationScalars.

    .OUTPUTS
    The new PSCustomObject containing scalars

    .PARAMETER Observation
    The observation hashtable from New-Observation

    .PARAMETER Scalars
    An array of scalars from New-Scalar

    .LINK
    New-Observation
    New-Scalar
#>

function New-ObservationScalars {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline)]
        [ValidateNotNull()]
        [PSCustomObject]
        $Observation,

        [Parameter(Mandatory = $true, Position = 1)]
        [ValidateNotNull()]
        [PSCustomObject[]]
        $Scalars
    )
    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }

    process {
        Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

        $post = @{}
        $post.body = @{ "observation" = $Observation }
        $i = 1
        $Scalars | ForEach-Object { $post.body."scalar-$($i)" = $_; $i++ } | Out-Null
        Write-Output $post
    }
}