Skip to content

Commit

Permalink
Merge pull request #33 from jonathanmedd/feature/add-pipeline-support
Browse files Browse the repository at this point in the history
Added pipeline support for Get-BricksetSet
  • Loading branch information
jonathanmedd authored Feb 15, 2021
2 parents 7a73881 + c34000a commit 2d21ca9
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions src/Functions/Public/Get-BricksetSet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@

Param (

[parameter(Mandatory = $false)]
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[String]$theme,

[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]$subTheme,

[parameter(Mandatory = $false)]
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
$year,

Expand All @@ -73,57 +73,63 @@
[Int]$pageSize = 500
)

try {
begin {

# --- Check for the presence of $Script:BricksetConnection
xCheckScriptBricksetConnection
}

# - Prepare the JSON params
$jsonParams = [PSCustomObject] @{
process {

pageSize = $pageSize
}
try {

if ($PSBoundParameters.ContainsKey('theme')) {
# - Prepare the JSON params
$jsonParams = [PSCustomObject] @{

$jsonParams | Add-Member -MemberType NoteProperty -Name 'theme' -Value $theme
}
if ($PSBoundParameters.ContainsKey('subTheme')) {
pageSize = $pageSize
}

$jsonParams | Add-Member -MemberType NoteProperty -Name 'subtheme' -Value $subTheme
}
if ($PSBoundParameters.ContainsKey('year')) {
if ($PSBoundParameters.ContainsKey('theme')) {

$jsonParams | Add-Member -MemberType NoteProperty -Name 'year' -Value $year
}
if ($PSBoundParameters.ContainsKey('setNumber')) {
$jsonParams | Add-Member -MemberType NoteProperty -Name 'theme' -Value $theme
}
if ($PSBoundParameters.ContainsKey('subTheme')) {

$jsonParams | Add-Member -MemberType NoteProperty -Name 'setNumber' -Value $setNumber
}
if ($PSBoundParameters.ContainsKey('orderBy')) {
$jsonParams | Add-Member -MemberType NoteProperty -Name 'subtheme' -Value $subTheme
}
if ($PSBoundParameters.ContainsKey('year')) {

$jsonParams | Add-Member -MemberType NoteProperty -Name 'orderBy' -Value $orderBy
}
$jsonParams | Add-Member -MemberType NoteProperty -Name 'year' -Value $year
}
if ($PSBoundParameters.ContainsKey('setNumber')) {

$stringParam = $jsonParams | ConvertTo-Json -Compress
$jsonParams | Add-Member -MemberType NoteProperty -Name 'setNumber' -Value $setNumber
}
if ($PSBoundParameters.ContainsKey('orderBy')) {

Write-Verbose "jsonParams are: $stringParam"
$jsonParams | Add-Member -MemberType NoteProperty -Name 'orderBy' -Value $orderBy
}

# --- Make the REST Call
$body = @{
apiKey = $Script:BricksetConnection.apiKey
userHash = $null
params = $stringParam
}
$stringParam = $jsonParams | ConvertTo-Json -Compress

Write-Verbose "Body is: $($body | ConvertTo-Json -Depth 5)"
Write-Verbose "jsonParams are: $stringParam"

$response = Invoke-BricksetRestMethod -Method POST -URI '/getSets' -Body $body
# --- Make the REST Call
$body = @{
apiKey = $Script:BricksetConnection.apiKey
userHash = $null
params = $stringParam
}

$response.sets
}
catch [Exception] {
Write-Verbose "Body is: $($body | ConvertTo-Json -Depth 5)"

$response = Invoke-BricksetRestMethod -Method POST -URI '/getSets' -Body $body

throw
$response.sets
}
catch [Exception] {

throw
}
}
}

0 comments on commit 2d21ca9

Please sign in to comment.