Public/Set-SignRequest.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<#
.SYNOPSIS
Sets request properties
#>

function Set-SignRequest {
    [CmdletBinding(SupportsShouldProcess)]
    param (
        # Sign request id
        [Parameter(Mandatory=$true)]
        [string]
        $id,

        # Title
        [Parameter(Mandatory=$false)]
        [string]
        $title,

        # Description
        [Parameter(Mandatory=$false)]
        [string]
        $description,

        # autoAchive
        [Parameter(Mandatory=$false)]
        [bool]
        $autoArchive,

        #Message for the archivist
        [Parameter(Mandatory=$false)]
        [string]
        $archiveDescription,

        #Request due date
        [Parameter(Mandatory=$false)]
        [datetime]
        $dueDate,

        #Ending notification period in days. How may days before due date an automatic reminder is sent to the user. Zero means "no notification will be sent"
        [Parameter(Mandatory=$false)]
        [Int32]
        $notificationDays,

        # sendMail
        [Parameter(Mandatory=$false)]
        [bool]
        $sendMail,

        # combineDocuments
        [Parameter(Mandatory=$false)]
        [bool]
        $combineDocuments,

        #Valid user proofing methods
        [Parameter(Mandatory=$false)]
        [validateSet('NONE','BASIC','STRONG','ADVANCED','AUTOGEN')]
        [string[]]
        $validProofTypes,

        #Proofing scope
        [Parameter(Mandatory=$false)]
        [validateSet('All','Invitees only')]
        $proofScope,

        # custom attributes for signing request
        [Parameter(Mandatory=$false)]
        [hashtable]
        $attributes

    )

    begin {
        $api = "/request/$id"
        $Body = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
        Write-Verbose "Set-SignRequest body: $($Body | Convertto-json)"
        if ($Body['attributes']) {
            $Body['attributes'] = [array](ConvertTo-NameValues -hashtable $Body['attributes'])
        }

        if($proofScope){
            $body['proofScope'] = @{'All' = 0; 'Invitees only' = 1}[$proofScope]
        }

        if($validProofTypes){
            for ($j = 0; $j -lt ([array]$validProofTypes).Count ; $j++){
                $body['validProofTypes'][$j] = @{'NONE' = 0;'BASIC'=1 ;'STRONG' = 2;'ADVANCED' = 3;'AUTOGEN'= 4}[([array]$validProofTypes)[$j]]
            }
        }

        if($dueDate) {
            $body['dueDate'] = [string](get-date $body['dueDate'] -Uformat "%Y-%m-%dT%H:%M:%S.000Z")
        }
    }

    process {
        if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
            $result = Invoke-SignApi -body $Body -api $api -method 'PUT'
            if ($result.request) {
                $result.request
            }
        }
    }

    end {

    }
}