Functions/Public/Get-BricksetRecentlyUpdatedSet.psm1

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
function Get-BricksetRecentlyUpdatedSet {
<#
    .SYNOPSIS
    Get Brickset Sets that have recently changed
    
    .DESCRIPTION
    Get Brickset Sets that have recently changed

    .PARAMETER HoursAgo
    Number of hours to search back for

    .PARAMETER DaysAgo
    Number of days to search back for

    .PARAMETER WeeksAgo
    Number of weeks to search back for

    .PARAMETER MonthsAgo
    Number of months to search back for

    .INPUTS
    System.String.
    System.Int

    .OUTPUTS
    Brickset.sets

    .EXAMPLE
    Get-BricksetRecentlyUpdatedSet -DaysAgo 5
#>

[CmdletBinding(DefaultParameterSetName='HoursAgo')][OutputType('Brickset.sets')]

    Param
    (

    [parameter(Mandatory=$true,ParameterSetName='HoursAgo')]
    [ValidateNotNullOrEmpty()]
    [Int]$HoursAgo,

    [parameter(Mandatory=$true,ParameterSetName='DaysAgo')]
    [ValidateNotNullOrEmpty()]
    [Int]$DaysAgo,

    [parameter(Mandatory=$true,ParameterSetName='WeeksAgo')]
    [ValidateNotNullOrEmpty()]
    [Int]$WeeksAgo,

    [parameter(Mandatory=$true,ParameterSetName='MonthsAgo')]
    [ValidateNotNullOrEmpty()]
    [Int]$MonthsAgo
    )    

    try {

        # --- Check for the presence of $Global:BricksetConnection
        xCheckGlobalBricksetConnection

        # --- Determine time to look back for
        switch ($PsCmdlet.ParameterSetName) 
        { 
            "HoursAgo"  { $MinutesAgo = $HoursAgo * 60; break} 
            "DaysAgo"  { $MinutesAgo = $DaysAgo * 60 * 24; break}
            "WeeksAgo"  { $MinutesAgo = $WeeksAgo * 60 * 24 * 7; break} 
            "MonthsAgo"  { $MinutesAgo = ((Get-Date) - ((Get-Date).AddMonths($MonthsAgo * -1))).TotalMinutes; break}  
        }

        # --- Make the Webservice Call
        $BricksetConnection.WebService.getRecentlyUpdatedSets($BricksetConnection.APIKey,$MinutesAgo)
    }
    catch [Exception]{
            
        throw
    }
}