From c860da790f22032a3d139383ce47797c58737337 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 20:57:27 +0000 Subject: [PATCH] change structure --- ...{Invoke-Method.psm1 => Invoke-Method.psd1} | 0 SnipeitPS/Public/Assets.psm1 | 177 ------------------ SnipeitPS/Public/Get-Asset.psd1 | 40 ++++ .../{Categories.psm1 => Get-Category.psd1} | 0 .../{Components.psm1 => Get-Component.psd1} | 0 ...nufacturers.psm1 => Get-Manufacturer.psm1} | 0 SnipeitPS/Public/Get-Model.psd1 | 16 ++ .../Public/{Status.psm1 => Get-Status.psd1} | 0 .../Public/{Users.psm1 => Get-User.psm1} | 0 SnipeitPS/Public/Models.psm1 | 68 ------- SnipeitPS/Public/New-Asset.psd1 | 50 +++++ SnipeitPS/Public/New-Component.psd1 | 76 ++++++++ SnipeitPS/Public/New-Manufacturer.psd1 | 40 ++++ SnipeitPS/Public/New-Model.psd1 | 50 +++++ SnipeitPS/Public/Set-Asset.psd1 | 52 +++++ SnipeitPS/Public/Set-AssetOwner.psd1 | 41 ++++ SnipeitPS/Public/Set-Components.psd1 | 41 ++++ .../Public/{Set-Info.psm1 => Set-Info.ps1} | 0 SnipeitPS/SnipeItPS.psm1 | 6 +- Tests/SnipeItPS.Tests.ps1 | 1 - 20 files changed, 409 insertions(+), 249 deletions(-) rename SnipeitPS/Private/{Invoke-Method.psm1 => Invoke-Method.psd1} (100%) delete mode 100644 SnipeitPS/Public/Assets.psm1 create mode 100644 SnipeitPS/Public/Get-Asset.psd1 rename SnipeitPS/Public/{Categories.psm1 => Get-Category.psd1} (100%) rename SnipeitPS/Public/{Components.psm1 => Get-Component.psd1} (100%) rename SnipeitPS/Public/{Manufacturers.psm1 => Get-Manufacturer.psm1} (100%) create mode 100644 SnipeitPS/Public/Get-Model.psd1 rename SnipeitPS/Public/{Status.psm1 => Get-Status.psd1} (100%) rename SnipeitPS/Public/{Users.psm1 => Get-User.psm1} (100%) delete mode 100644 SnipeitPS/Public/Models.psm1 create mode 100644 SnipeitPS/Public/New-Asset.psd1 create mode 100644 SnipeitPS/Public/New-Component.psd1 create mode 100644 SnipeitPS/Public/New-Manufacturer.psd1 create mode 100644 SnipeitPS/Public/New-Model.psd1 create mode 100644 SnipeitPS/Public/Set-Asset.psd1 create mode 100644 SnipeitPS/Public/Set-AssetOwner.psd1 create mode 100644 SnipeitPS/Public/Set-Components.psd1 rename SnipeitPS/Public/{Set-Info.psm1 => Set-Info.ps1} (100%) diff --git a/SnipeitPS/Private/Invoke-Method.psm1 b/SnipeitPS/Private/Invoke-Method.psd1 similarity index 100% rename from SnipeitPS/Private/Invoke-Method.psm1 rename to SnipeitPS/Private/Invoke-Method.psd1 diff --git a/SnipeitPS/Public/Assets.psm1 b/SnipeitPS/Public/Assets.psm1 deleted file mode 100644 index e8d0e75..0000000 --- a/SnipeitPS/Public/Assets.psm1 +++ /dev/null @@ -1,177 +0,0 @@ -<# -.SYNOPSIS -# Gets a list of Snipe-it Assets - -.PARAMETER url -URL of Snipeit system, can be set using Set-Info command - -.PARAMETER apiKey -Users API Key for Snipeit, can be set using Set-Info command - -.EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." - -.EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } - -#> - -function Get-Asset() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/hardware" ` - -Method GET ` - -Token $apiKey - - $result -} - -function New-Asset() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$Name, - - [parameter(mandatory=$true)] - [string]$Status_id, - - [parameter(mandatory=$true)] - [string]$Model_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey, - - [hashtable] $customfields - ) - - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - $Values += $customfields - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware" - Method = 'Post' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -function Set-Asset() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [int]$id, - - [parameter(mandatory=$true)] - [string]$Name, - - [parameter(mandatory=$true)] - [string]$Status_id, - - [parameter(mandatory=$true)] - [string]$Model_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey, - - [hashtable] $customfields - ) - - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - $Values += $customfields - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware/$id" - Method = 'Put' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -function Set-AssetOwner() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [int]$id, - - [parameter(mandatory=$true)] - [int]$user_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - "user_id" = $user_id - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware/$id/checkout" - Method = 'POST' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - return $result -} diff --git a/SnipeitPS/Public/Get-Asset.psd1 b/SnipeitPS/Public/Get-Asset.psd1 new file mode 100644 index 0000000..894e251 --- /dev/null +++ b/SnipeitPS/Public/Get-Asset.psd1 @@ -0,0 +1,40 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Assets + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Asset -url "https://assets.dip.co.uk" -token "token..." + +.EXAMPLE +Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } + +#> + +function Get-Asset() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $result = Invoke-Method -URi "$url/api/v1/hardware" ` + -Method GET ` + -Token $apiKey + + $result +} + + + + + + diff --git a/SnipeitPS/Public/Categories.psm1 b/SnipeitPS/Public/Get-Category.psd1 similarity index 100% rename from SnipeitPS/Public/Categories.psm1 rename to SnipeitPS/Public/Get-Category.psd1 diff --git a/SnipeitPS/Public/Components.psm1 b/SnipeitPS/Public/Get-Component.psd1 similarity index 100% rename from SnipeitPS/Public/Components.psm1 rename to SnipeitPS/Public/Get-Component.psd1 diff --git a/SnipeitPS/Public/Manufacturers.psm1 b/SnipeitPS/Public/Get-Manufacturer.psm1 similarity index 100% rename from SnipeitPS/Public/Manufacturers.psm1 rename to SnipeitPS/Public/Get-Manufacturer.psm1 diff --git a/SnipeitPS/Public/Get-Model.psd1 b/SnipeitPS/Public/Get-Model.psd1 new file mode 100644 index 0000000..4c4d92f --- /dev/null +++ b/SnipeitPS/Public/Get-Model.psd1 @@ -0,0 +1,16 @@ +function Get-Model() +{ + Param( + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $result = Invoke-Method -URi "$url/api/v1/models" ` + -Method GET ` + -Token $apiKey + + $result +} diff --git a/SnipeitPS/Public/Status.psm1 b/SnipeitPS/Public/Get-Status.psd1 similarity index 100% rename from SnipeitPS/Public/Status.psm1 rename to SnipeitPS/Public/Get-Status.psd1 diff --git a/SnipeitPS/Public/Users.psm1 b/SnipeitPS/Public/Get-User.psm1 similarity index 100% rename from SnipeitPS/Public/Users.psm1 rename to SnipeitPS/Public/Get-User.psm1 diff --git a/SnipeitPS/Public/Models.psm1 b/SnipeitPS/Public/Models.psm1 deleted file mode 100644 index caa093e..0000000 --- a/SnipeitPS/Public/Models.psm1 +++ /dev/null @@ -1,68 +0,0 @@ - -function Get-Model() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/models" ` - -Method GET ` - -Token $apiKey - - $result -} - - -function New-Model() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$name, - - [parameter(mandatory=$true)] - [int]$category_id, - - [parameter(mandatory=$true)] - [int]$manufacturer_id, - - [parameter(mandatory=$true)] - [int]$fieldset_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - name = $name - category_id = $category_id - manufacturer_id = $manufacturer_id - fieldset_id = $fieldset_id - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/models" - Method = 'post' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} diff --git a/SnipeitPS/Public/New-Asset.psd1 b/SnipeitPS/Public/New-Asset.psd1 new file mode 100644 index 0000000..3ac8d95 --- /dev/null +++ b/SnipeitPS/Public/New-Asset.psd1 @@ -0,0 +1,50 @@ +function New-Asset() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$Status_id, + + [parameter(mandatory = $true)] + [string]$Model_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey, + + [hashtable] $customfields + ) + + $Values = @{ + "name" = $Name + "status_id" = $status_id + "model_id" = $model_id + } + + $Values += $customfields + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware" + Method = 'Post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/New-Component.psd1 b/SnipeitPS/Public/New-Component.psd1 new file mode 100644 index 0000000..92227ee --- /dev/null +++ b/SnipeitPS/Public/New-Component.psd1 @@ -0,0 +1,76 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER name + Parameter description + + .PARAMETER category_id + Parameter description + + .PARAMETER qty + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes +#> + +function New-Component() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [string]$category_id, + + [parameter(mandatory = $true)] + [string]$qty, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "name" = $name + "category_id" = $category_id + "qty" = $qty + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/components" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/New-Manufacturer.psd1 b/SnipeitPS/Public/New-Manufacturer.psd1 new file mode 100644 index 0000000..cbbab4a --- /dev/null +++ b/SnipeitPS/Public/New-Manufacturer.psd1 @@ -0,0 +1,40 @@ +function New-Manufacturer() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + + $Values = @{ + "name" = $Name + } + + #Convert Values to JSON format + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/manufacturers" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/New-Model.psd1 b/SnipeitPS/Public/New-Model.psd1 new file mode 100644 index 0000000..eec0272 --- /dev/null +++ b/SnipeitPS/Public/New-Model.psd1 @@ -0,0 +1,50 @@ +function New-Model() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [int]$category_id, + + [parameter(mandatory = $true)] + [int]$manufacturer_id, + + [parameter(mandatory = $true)] + [int]$fieldset_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + name = $name + category_id = $category_id + manufacturer_id = $manufacturer_id + fieldset_id = $fieldset_id + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/models" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-Asset.psd1 b/SnipeitPS/Public/Set-Asset.psd1 new file mode 100644 index 0000000..39b88d6 --- /dev/null +++ b/SnipeitPS/Public/Set-Asset.psd1 @@ -0,0 +1,52 @@ +function Set-Asset() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$Status_id, + + [parameter(mandatory = $true)] + [string]$Model_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey, + + [hashtable] $customfields + ) + + $Values = @{ + "name" = $Name + "status_id" = $status_id + "model_id" = $model_id + } + + $Values += $customfields + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-AssetOwner.psd1 b/SnipeitPS/Public/Set-AssetOwner.psd1 new file mode 100644 index 0000000..18308b0 --- /dev/null +++ b/SnipeitPS/Public/Set-AssetOwner.psd1 @@ -0,0 +1,41 @@ +function Set-AssetOwner() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [parameter(mandatory = $true)] + [int]$user_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "user_id" = $user_id + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id/checkout" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + return $result +} diff --git a/SnipeitPS/Public/Set-Components.psd1 b/SnipeitPS/Public/Set-Components.psd1 new file mode 100644 index 0000000..0cd2126 --- /dev/null +++ b/SnipeitPS/Public/Set-Components.psd1 @@ -0,0 +1,41 @@ +function Set-Component() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$id, + + [parameter(mandatory = $true)] + [string]$qty, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "qty" = $qty + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/components/$component_id" + Method = 'Patch' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-Info.psm1 b/SnipeitPS/Public/Set-Info.ps1 similarity index 100% rename from SnipeitPS/Public/Set-Info.psm1 rename to SnipeitPS/Public/Set-Info.ps1 diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeItPS.psm1 index 53f791c..4f4be07 100644 --- a/SnipeitPS/SnipeItPS.psm1 +++ b/SnipeitPS/SnipeItPS.psm1 @@ -1,11 +1,11 @@ $scriptRoot = $PSScriptRoot + '\public' -Get-ChildItem $scriptRoot *.psm1 | ForEach-Object { +Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { Import-Module $_.FullName } $scriptRoot = $PSScriptRoot + '\private' -Get-ChildItem $scriptRoot *.psm1 | ForEach-Object { +Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { Import-Module $_.FullName -} \ No newline at end of file +} diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index fb53815..010c077 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -8,7 +8,6 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1" $changelogFile = "$projectRoot\CHANGELOG.md" $appveyorFile = "$projectRoot\appveyor.yml" $publicFunctions = "$moduleRoot\Public" -$internalFunctions = "$moduleRoot\Internal" Describe "SnipeitPS" { Context "All required tests are present" {