Skip to content

Commit 7b6db0a

Browse files
authored
Merge pull request #5 from IronstoneIT/master
Improvements to INT values, readability and minor code optimalizations
2 parents 973fab2 + fb022ce commit 7b6db0a

22 files changed

+884
-999
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,96 @@
11
function New-ITGlueConfigurationInterfaces {
22
Param (
3-
[Nullable[Int]]$conf_id = $null,
3+
[Nullable[Int64]]$conf_id = $null,
44

5-
[Parameter(Mandatory=$true)]
5+
[Parameter(Mandatory = $true)]
66
$data
77
)
88

9-
$resource_uri = "/configuration_interfaces/"
9+
$resource_uri = '/configuration_interfaces/'
1010

11-
if($conf_id) {
12-
$resource_uri = "/configurations/${conf_id}/relationships/configuration_interfaces"
11+
if ($conf_id) {
12+
$resource_uri = ('/configurations/{0}/relationships/configuration_interfaces' -f $conf_id)
1313
}
1414

15-
$body = ConvertTo-Json $data -Depth $ITGlue_JSON_Conversion_Depth
15+
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
1616

17-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
18-
$rest_output = Invoke-RestMethod -method "POST" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
19-
-body $body -ErrorAction Stop -ErrorVariable $web_error
17+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
18+
$rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
19+
-body $body -ErrorAction Stop -ErrorVariable $web_error
2020
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
2121

2222
$data = @{}
2323
$data = $rest_output
2424
return $data
2525
}
2626

27-
28-
29-
3027
function Get-ITGlueConfigurationInterfaces {
31-
[CmdletBinding(DefaultParametersetName="index")]
28+
[CmdletBinding(DefaultParametersetName = 'index')]
3229
Param (
33-
[Parameter(ParameterSetName="index")]
34-
[Parameter(ParameterSetName="show")]
35-
[Nullable[Int]]$conf_id = $null,
30+
[Parameter(ParameterSetName = 'index')]
31+
[Parameter(ParameterSetName = 'show')]
32+
[Nullable[Int64]]$conf_id = $null,
3633

37-
[Parameter(ParameterSetName="index")]
38-
[Nullable[Int]]$page_number = $null,
34+
[Parameter(ParameterSetName = 'index')]
35+
[Nullable[Int64]]$page_number = $null,
3936

40-
[Parameter(ParameterSetName="index")]
37+
[Parameter(ParameterSetName = 'index')]
4138
[Nullable[int]]$page_size = $null,
4239

43-
[Parameter(ParameterSetName="show")]
44-
[Nullable[Int]]$id = $null
40+
[Parameter(ParameterSetName = 'show')]
41+
[Nullable[Int64]]$id = $null
4542
)
4643

47-
$resource_uri = "/configurations/${conf_id}/relationships/configuration_interfaces/${id}"
48-
if(($PsCmdlet.ParameterSetName -eq "show") -and ($conf_id -eq $null)) {
49-
$resource_uri = "/configuration_interfaces/${id}"
44+
$resource_uri = ('/configurations/{0}/relationships/configuration_interfaces/{1}' -f $conf_id, $id)
45+
if (($PsCmdlet.ParameterSetName -eq 'show') -and ($conf_id -eq $null)) {
46+
$resource_uri = ('/configuration_interfaces/{0}' -f $id)
5047
}
5148

52-
if($PSCmdlet.ParameterSetName -eq "index") {
49+
if ($PSCmdlet.ParameterSetName -eq 'index') {
5350
$body = @{}
54-
if($page_number) {
55-
$body += @{"page[number]" = $page_number}
51+
if ($page_number) {
52+
$body += @{'page[number]' = $page_number}
5653
}
57-
if($page_size) {
58-
$body += @{"page[size]" = $page_size}
54+
if ($page_size) {
55+
$body += @{'page[size]' = $page_size}
5956
}
6057
}
6158

6259

63-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
64-
$rest_output = Invoke-RestMethod -method "GET" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
65-
-body $body -ErrorAction Stop -ErrorVariable $web_error
60+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
61+
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
62+
-body $body -ErrorAction Stop -ErrorVariable $web_error
6663
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
6764

6865
$data = @{}
6966
$data = $rest_output
7067
return $data
7168
}
7269

73-
74-
75-
7670
function Set-ITGlueConfigurationInterfaces {
7771
Param (
78-
[Nullable[Int]]$id,
72+
[Nullable[Int64]]$id,
7973

80-
[Nullable[Int]]$conf_id = $null,
74+
[Nullable[Int64]]$conf_id = $null,
8175

82-
[Parameter(Mandatory=$true)]
76+
[Parameter(Mandatory = $true)]
8377
$data
8478
)
8579

86-
$resource_uri = "/configuration_interfaces/${id}"
80+
$resource_uri = ('/configuration_interfaces/{0}' -f $id)
8781

88-
if($conf_id) {
89-
$resource_uri = "/configurations/${conf_id}/relationships/configuration_interfaces/${id}"
82+
if ($conf_id) {
83+
$resource_uri = ('/configurations/{0}/relationships/configuration_interfaces/{1}' -f $conf_id, $id)
9084
}
9185

92-
$body = ConvertTo-Json $data -Depth $ITGlue_JSON_Conversion_Depth
86+
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
9387

94-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
95-
$rest_output = Invoke-RestMethod -method "PATCH" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
96-
-body $body -ErrorAction Stop -ErrorVariable $web_error
88+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
89+
$rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
90+
-body $body -ErrorAction Stop -ErrorVariable $web_error
9791
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
9892

9993
$data = @{}
10094
$data = $rest_output
10195
return $data
102-
}
96+
}

ITGlueAPI/Resources/ConfigurationStatuses.ps1

+37-44
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,86 @@
11
function New-ITGlueConfigurationStatuses {
22
Param (
3-
[Parameter(Mandatory=$true)]
3+
[Parameter(Mandatory = $true)]
44
$data
55
)
66

7-
$resource_uri = "/configuration_statuses/"
7+
$resource_uri = '/configuration_statuses/'
88

9-
$body = ConvertTo-Json $data -Depth $ITGlue_JSON_Conversion_Depth
9+
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
1010

11-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
12-
$rest_output = Invoke-RestMethod -method "POST" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
13-
-body $body -ErrorAction Stop -ErrorVariable $web_error
11+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
12+
$rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
13+
-body $body -ErrorAction Stop -ErrorVariable $web_error
1414
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
1515

1616
$data = @{}
1717
$data = $rest_output
1818
return $data
1919
}
2020

21-
22-
23-
2421
function Get-ITGlueConfigurationStatuses {
25-
[CmdletBinding(DefaultParameterSetName="index")]
22+
[CmdletBinding(DefaultParameterSetName = 'index')]
2623
Param (
27-
[Parameter(ParameterSetName="index")]
28-
[String]$filter_name = "",
24+
[Parameter(ParameterSetName = 'index')]
25+
[String]$filter_name = '',
2926

30-
[Parameter(ParameterSetName="index")]
31-
[ValidateSet( "name", "id", `
32-
"-name", "-id")]
33-
[String]$sort = "",
27+
[Parameter(ParameterSetName = 'index')]
28+
[ValidateSet( 'name', 'id', `
29+
'-name', '-id')]
30+
[String]$sort = '',
3431

35-
[Parameter(ParameterSetName="index")]
36-
[Nullable[Int]]$page_number = $null,
32+
[Parameter(ParameterSetName = 'index')]
33+
[Nullable[Int64]]$page_number = $null,
3734

38-
[Parameter(ParameterSetName="index")]
35+
[Parameter(ParameterSetName = 'index')]
3936
[Nullable[int]]$page_size = $null,
4037

41-
[Parameter(ParameterSetName="show")]
42-
[Nullable[Int]]$id = $null
38+
[Parameter(ParameterSetName = 'show')]
39+
[Nullable[Int64]]$id = $null
4340
)
4441

45-
$resource_uri = "/configuration_statuses/${id}"
42+
$resource_uri = ('/configuration_statuses/{0}' -f $id)
4643

47-
if($PSCmdlet.ParameterSetName -eq "index") {
44+
if ($PSCmdlet.ParameterSetName -eq 'index') {
4845
$body = @{
49-
"filter[name]" = $filter_name
50-
"sort" = $sort
46+
'filter[name]' = $filter_name
47+
'sort' = $sort
5148
}
52-
if($page_number) {
53-
$body += @{"page[number]" = $page_number}
49+
if ($page_number) {
50+
$body += @{'page[number]' = $page_number}
5451
}
55-
if($page_size) {
56-
$body += @{"page[size]" = $page_size}
52+
if ($page_size) {
53+
$body += @{'page[size]' = $page_size}
5754
}
5855
}
5956

6057

61-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
62-
$rest_output = Invoke-RestMethod -method "GET" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
63-
-body $body -ErrorAction Stop -ErrorVariable $web_error
58+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
59+
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
60+
-body $body -ErrorAction Stop -ErrorVariable $web_error
6461
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
6562

6663
$data = @{}
6764
$data = $rest_output
6865
return $data
6966
}
7067

71-
72-
73-
74-
7568
function Set-ITGlueConfigurationStatuses {
7669
Param (
77-
[Parameter(Mandatory=$true)]
78-
[Int]$id,
70+
[Parameter(Mandatory = $true)]
71+
[Int64]$id,
7972

80-
[Parameter(Mandatory=$true)]
73+
[Parameter(Mandatory = $true)]
8174
$data
8275
)
8376

84-
$resource_uri = "/configuration_statuses/${id}"
77+
$resource_uri = ('/configuration_statuses/{0}' -f $id)
8578

86-
$body = ConvertTo-Json $data -Depth $ITGlue_JSON_Conversion_Depth
79+
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
8780

88-
$ITGlue_Headers.Add("x-api-key", (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
89-
$rest_output = Invoke-RestMethod -method "PATCH" -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
90-
-body $body -ErrorAction Stop -ErrorVariable $web_error
81+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
82+
$rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
83+
-body $body -ErrorAction Stop -ErrorVariable $web_error
9184
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
9285

9386
$data = @{}

0 commit comments

Comments
 (0)