Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit 484de2b

Browse files
author
treestryder
committed
Added Get-WorkdayWorkerPhoto.
1 parent 440ec06 commit 484de2b

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

source/WorkdayApi.psd1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ModuleVersion = '2.3.0'
44
HelpInfoURI = 'https://github.com/treestryder/powershell_module_workdayapi/wiki'
55
Author = 'Nathan Hartley'
6-
Copyright = '(c) 2019 Nathan Hartley. All rights reserved.'
6+
Copyright = '(c) 2020 Nathan Hartley. All rights reserved.'
77
RootModule = 'WorkdayApi.psm1'
88
PowerShellVersion = '5.1'
99
CompatiblePSEditions = @('Desktop', 'Core')
@@ -12,7 +12,11 @@
1212
Tags = @('Workday')
1313
LicenseUri = 'https://github.com/treestryder/powershell_module_workdayapi/blob/master/source/License.txt'
1414
ProjectUri = 'https://github.com/treestryder/powershell_module_workdayapi/'
15-
ReleaseNotes = 'Inital release to the Powershell Gallery.'
15+
ReleaseNotes = @'
16+
* Added Get-WorkdayWorkerPhoto for getting worker's photo.
17+
18+
Change log available at: https://github.com/treestryder/powershell_module_workdayapi/blob/master/CHANGELOG.md
19+
'@
1620
}
1721
}
1822
FunctionsToExport = @(

source/public/Get-WorkdayWorkerPhoto.ps1

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ function Get-WorkdayWorkerPhoto {
1313
The type of ID that the WorkerId represents. Valid values
1414
are 'WID', 'Contingent_Worker_ID' and 'Employee_ID'.
1515
16+
.PARAMETER Path
17+
Path to save the photo. If Path is to a directory, the file name from Workday will be appened.
18+
If no Path is specified, a PsCustomObject is returned containing the file name and byte array.
19+
1620
.PARAMETER Passthru
1721
Outputs Invoke-WorkdayRequest object, rather than a custom Worker object.
22+
If desired, the Base 64 encoded image and file name can be aquired from the XML.
1823
1924
.PARAMETER Human_ResourcesUri
2025
Human_Resources Endpoint Uri for the request. If not provided, the value
@@ -30,7 +35,12 @@ function Get-WorkdayWorkerPhoto {
3035
3136
.EXAMPLE
3237
33-
Get-WorkdayWorkerPhoto -WorkerId 123
38+
# Get the Binary Array of a
39+
$BinaryArray = Get-WorkdayWorkerPhoto -WorkerId 123
40+
41+
.EXAMPLE
42+
#
43+
3444
3545
#>
3646

@@ -49,9 +59,11 @@ Get-WorkdayWorkerPhoto -WorkerId 123
4959
ParameterSetName='IndividualWorker')]
5060
[ValidateSet('WID', 'Contingent_Worker_ID', 'Employee_ID')]
5161
[string]$WorkerType = 'Employee_ID',
62+
[string]$Path,
63+
[switch]$Passthru,
5264
[string]$Human_ResourcesUri,
5365
[string]$Username,
54-
[string]$Password,
66+
[string]$Password,
5567
[DateTime]$AsOfEntryDateTime = (Get-Date)
5668
)
5769

@@ -83,12 +95,30 @@ Get-WorkdayWorkerPhoto -WorkerId 123
8395
}
8496
$response = Invoke-WorkdayRequest -Request $request -Uri $Human_ResourcesUri -Username:$Username -Password:$Password
8597

86-
$o = [PSCustomObject][ordered]@{
87-
ID = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.ID
88-
Photo = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.File
98+
if ($Passthru) {
99+
Write-Output $response
100+
}
101+
elseif ($response.Success) {
102+
$filename = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.Filename
103+
$base64 = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.File
104+
$bytes = [System.Convert]::FromBase64String($base64)
105+
106+
if ([string]::IsNullOrEmpty($Path)) {
107+
$output = [PsCustomObject][Ordered]@{
108+
Filename = $filename
109+
Bytes = $bytes
110+
}
111+
Write-Output $output
112+
}
113+
else {
114+
if (Test-Path -Path $Path -PathType Container) {
115+
$Path = Join-Path $Path $filename
116+
}
117+
$bytes | Set-Content -Path $Path -Encoding Byte
118+
}
119+
}
120+
else {
121+
throw "Error calling Get_Worker_Photos_Request: $($response.Message)"
89122
}
90-
91-
92-
Write-Output $o
93123
}
94-
}
124+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Get-Module WorkdayApi | Remove-Module -Force
2+
Import-Module "$PsScriptRoot\..\WorkdayApi.psd1" -Force
3+
Import-Module "$PsScriptRoot\Invoke-WorkdayRequestHelper.psm1" -Force -DisableNameChecking
4+
5+
Describe Get-WorkdayWorkerPhoto {
6+
InModuleScope WorkdayApi {
7+
8+
# Echo Request
9+
Mock Invoke-WorkdayRequest {
10+
Mock_Invoke-WorkdayRequest_Echo @args
11+
}
12+
13+
It 'Creates the correct XML for the request.' {
14+
$expectedResponse = @'
15+
<bsvc:Get_Worker_Photos_Request bsvc:version="v30.0" xmlns:bsvc="urn:com.workday/bsvc"><bsvc:Request_References bsvc:Skip_Non_Existing_Instances="false"><bsvc:Worker_Reference><bsvc:ID bsvc:type="Employee_ID">1</bsvc:ID></bsvc:Worker_Reference></bsvc:Request_References><bsvc:Response_Filter><bsvc:As_Of_Entry_DateTime>2020-05-05T00:00:00.0000000</bsvc:As_Of_Entry_DateTime></bsvc:Response_Filter></bsvc:Get_Worker_Photos_Request>
16+
'@ -f (Get-Date)
17+
$response = Get-WorkdayWorkerPhoto -WorkerId 1 -AsOfEntryDateTime '2020-05-05' -Passthru
18+
$response.Xml.OuterXml | Should BeExactly $expectedResponse
19+
}
20+
21+
}
22+
}

0 commit comments

Comments
 (0)