Skip to content

Commit 59fa72a

Browse files
author
ShocOne
committed
updated examples to align with struct changes
1 parent d88314f commit 59fa72a

File tree

7 files changed

+123
-83
lines changed

7 files changed

+123
-83
lines changed

examples/computer_groups/CreateSmartComputerGroup/CreateSmartComputerGroup.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ func main() {
3434
}
3535

3636
// Sample data for creating a new computer group (replace with actual data as needed)
37-
newSmartGroup := &jamfpro.ComputerGroupRequest{
37+
newSmartGroup := &jamfpro.ResponseComputerGroup{
3838
Name: "NewGroupNameBySDKWithnoSiteset",
3939
IsSmart: true,
40-
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"}, // not required in req as can be handled in func and set to none.
41-
Criteria: []jamfpro.ComputerGroupCriterion{
40+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
41+
Criteria: []jamfpro.CriterionContainer{
4242
{
43-
Name: "Last Inventory Update",
44-
Priority: 0,
45-
AndOr: jamfpro.And,
46-
SearchType: "more than x days ago",
47-
SearchValue: "7",
43+
Size: 1,
44+
Criterion: jamfpro.ComputerGroupCriterion{
45+
Name: "Last Inventory Update",
46+
Priority: 0,
47+
AndOr: jamfpro.And,
48+
SearchType: "more than x days ago",
49+
SearchValue: "7",
50+
},
4851
},
4952
},
5053
}

examples/computer_groups/CreateStaticComputerGroup/CreateStaticComputerGroup.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,31 @@ func main() {
3434
}
3535

3636
// Define the computers for the static group
37-
computers := []jamfpro.ComputerGroupComputerItem{
37+
computers := []jamfpro.ComputerContainer{
3838
{
39-
ID: 2,
40-
Name: "MacBook Pro",
41-
MacAddress: "",
42-
AltMacAddress: "",
43-
SerialNumber: "D2FHXH22QB",
39+
Size: 1,
40+
Computer: jamfpro.ComputerGroupComputerItem{
41+
ID: 2,
42+
Name: "MacBook Pro",
43+
MacAddress: "",
44+
AltMacAddress: "",
45+
SerialNumber: "D2FHXH22QB",
46+
},
4447
},
4548
{
46-
ID: 6,
47-
Name: "MacBook Pro",
48-
MacAddress: "",
49-
AltMacAddress: "",
50-
SerialNumber: "LT6M4DTF88",
49+
Size: 1,
50+
Computer: jamfpro.ComputerGroupComputerItem{
51+
ID: 6,
52+
Name: "MacBook Pro",
53+
MacAddress: "",
54+
AltMacAddress: "",
55+
SerialNumber: "LT6M4DTF88",
56+
},
5157
},
5258
}
5359

5460
// Create a new static computer group
55-
newStaticGroup := &jamfpro.ComputerGroupRequest{
61+
newStaticGroup := &jamfpro.ResponseComputerGroup{
5662
Name: "SDK Static Group Test",
5763
IsSmart: false,
5864
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},

examples/computer_groups/UpdateSmartComputerGroupByID/UpdateSmartComputerGroupByID.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ func main() {
3434
}
3535

3636
// Define the computer group details for update
37-
groupUpdate := &jamfpro.ComputerGroupRequest{
37+
groupUpdate := &jamfpro.ResponseComputerGroup{
3838
Name: "UpdatedGroupName",
3939
IsSmart: true,
40-
Criteria: []jamfpro.ComputerGroupCriterion{
40+
Criteria: []jamfpro.CriterionContainer{
4141
{
42-
Name: "Last Inventory Update",
43-
Priority: 0,
44-
AndOr: jamfpro.And,
45-
SearchType: "more than x days ago",
46-
SearchValue: "7",
42+
Size: 1,
43+
Criterion: jamfpro.ComputerGroupCriterion{
44+
Name: "Last Inventory Update",
45+
Priority: 0,
46+
AndOr: jamfpro.And,
47+
SearchType: "more than x days ago",
48+
SearchValue: "7",
49+
},
4750
},
4851
},
4952
}

examples/computer_groups/UpdateSmartComputerGroupByName/UpdateSmartComputerGroupByName.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ func main() {
3434
}
3535

3636
// Define the computer group name and details for update
37-
groupName := "NewGroupNameBySDK"
38-
groupUpdate := &jamfpro.ComputerGroupRequest{
39-
Name: "UpdatedNewGroupNameBySDK",
37+
groupName := "NewGroupNameBySDKWithnoSiteset"
38+
groupUpdate := &jamfpro.ResponseComputerGroup{
39+
Name: "UpdatedGroupNameBySDKWithnoSiteset",
4040
IsSmart: true,
41-
Criteria: []jamfpro.ComputerGroupCriterion{
41+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
42+
Criteria: []jamfpro.CriterionContainer{
4243
{
43-
Name: "Last Inventory Update",
44-
Priority: 0,
45-
AndOr: jamfpro.And,
46-
SearchType: "more than x days ago",
47-
SearchValue: "7",
44+
Size: 1,
45+
Criterion: jamfpro.ComputerGroupCriterion{
46+
Name: "Last Inventory Update",
47+
Priority: 0,
48+
AndOr: jamfpro.And,
49+
SearchType: "more than x days ago",
50+
SearchValue: "7",
51+
},
4852
},
4953
},
5054
}

examples/computer_groups/UpdateStaticComputerGroupByID/UpdateStaticComputerGroupByID.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,31 @@ func main() {
3737
groupID := 49 // Replace with your actual group ID
3838

3939
// Define the updated computers for the static group
40-
updatedComputers := []jamfpro.ComputerGroupComputerItem{
40+
updatedComputers := []jamfpro.ComputerContainer{
4141
{
42-
ID: 2,
43-
Name: "MacBook Pro",
44-
MacAddress: "",
45-
AltMacAddress: "",
46-
SerialNumber: "D2FCKL22FH",
42+
Size: 1,
43+
Computer: jamfpro.ComputerGroupComputerItem{
44+
ID: 2,
45+
Name: "MacBook Pro",
46+
MacAddress: "",
47+
AltMacAddress: "",
48+
SerialNumber: "D2FHXH22QB",
49+
},
50+
},
51+
{
52+
Size: 1,
53+
Computer: jamfpro.ComputerGroupComputerItem{
54+
ID: 6,
55+
Name: "MacBook Pro",
56+
MacAddress: "",
57+
AltMacAddress: "",
58+
SerialNumber: "LT6M4DTF88",
59+
},
4760
},
48-
// ... add more updated computers if needed
4961
}
5062

5163
// Create the updated static computer group data
52-
updatedStaticGroup := &jamfpro.ComputerGroupRequest{
64+
updatedStaticGroup := &jamfpro.ResponseComputerGroup{
5365
Name: "Updated Static Group Name",
5466
IsSmart: false,
5567
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},

examples/computer_groups/UpdateStaticComputerGroupByName/UpdateStaticComputerGroupByName.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,31 @@ func main() {
3737
groupName := "Updated Static Group Name" // Replace with your actual group name
3838

3939
// Define the updated computers for the static group
40-
updatedComputers := []jamfpro.ComputerGroupComputerItem{
40+
updatedComputers := []jamfpro.ComputerContainer{
4141
{
42-
ID: 2,
43-
Name: "MacBook Pro",
44-
MacAddress: "",
45-
AltMacAddress: "",
46-
SerialNumber: "D2FCXH22QW",
42+
Size: 1,
43+
Computer: jamfpro.ComputerGroupComputerItem{
44+
ID: 2,
45+
Name: "MacBook Pro",
46+
MacAddress: "",
47+
AltMacAddress: "",
48+
SerialNumber: "D2FHXH22QB",
49+
},
50+
},
51+
{
52+
Size: 1,
53+
Computer: jamfpro.ComputerGroupComputerItem{
54+
ID: 6,
55+
Name: "MacBook Pro",
56+
MacAddress: "",
57+
AltMacAddress: "",
58+
SerialNumber: "LT6M4DTF88",
59+
},
4760
},
48-
// ... add more updated computers if needed
4961
}
5062

5163
// Create the updated static computer group data
52-
updatedStaticGroup := &jamfpro.ComputerGroupRequest{
64+
updatedStaticGroup := &jamfpro.ResponseComputerGroup{
5365
Name: "Static Group Name",
5466
IsSmart: false,
5567
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},

sdk/jamfpro/classicapi_computer_groups.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ type ComputerGroupListItem struct {
2222
IsSmart bool `xml:"is_smart,omitempty"`
2323
}
2424

25-
type ComputerGroup struct {
26-
ID int `xml:"id"`
27-
Name string `xml:"name"`
28-
IsSmart bool `xml:"is_smart"`
29-
Site Site `xml:"site"`
30-
Criteria []ComputerGroupCriterion `xml:"criteria>criterion"`
31-
CriteriaSize int `xml:"criteria>size"`
32-
Computers []ComputerGroupComputerItem `xml:"computers>computer"`
33-
ComputerSize int `xml:"computers>size"`
25+
type ResponseComputerGroup struct {
26+
ID int `xml:"id"`
27+
Name string `xml:"name"`
28+
IsSmart bool `xml:"is_smart"`
29+
Site ComputerGroupSite `xml:"site"`
30+
Criteria []CriterionContainer `xml:"criteria>criterion_container"`
31+
Computers []ComputerContainer `xml:"computers>computer_container"`
3432
}
3533

36-
type ComputerGroupRequest struct {
37-
Name string `xml:"name"`
38-
IsSmart bool `xml:"is_smart"`
39-
Site ComputerGroupSite `xml:"site"`
40-
Criteria []ComputerGroupCriterion `xml:"criteria>criterion"`
41-
Computers []ComputerGroupComputerItem `xml:"computers>computer,omitempty"`
34+
type CriterionContainer struct {
35+
Size int `xml:"size"`
36+
Criterion ComputerGroupCriterion `xml:"criterion"`
37+
}
38+
39+
type ComputerContainer struct {
40+
Size int `xml:"size"`
41+
Computer ComputerGroupComputerItem `xml:"computer"`
4242
}
4343

4444
type ComputerGroupSite struct {
@@ -89,10 +89,10 @@ func (c *Client) GetComputerGroups() (*ComputerGroupsListResponse, error) {
8989
}
9090

9191
// GetComputerGroupByID retrieves a computer group by its ID.
92-
func (c *Client) GetComputerGroupByID(id int) (*ComputerGroup, error) {
92+
func (c *Client) GetComputerGroupByID(id int) (*ResponseComputerGroup, error) {
9393
endpoint := fmt.Sprintf("%s/id/%d", uriComputerGroups, id)
9494

95-
var group ComputerGroup
95+
var group ResponseComputerGroup
9696
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &group)
9797
if err != nil {
9898
return nil, fmt.Errorf("failed to fetch Computer Group by ID: %v", err)
@@ -106,10 +106,10 @@ func (c *Client) GetComputerGroupByID(id int) (*ComputerGroup, error) {
106106
}
107107

108108
// GetComputerGroupByName retrieves a computer group by its name.
109-
func (c *Client) GetComputerGroupByName(name string) (*ComputerGroup, error) {
109+
func (c *Client) GetComputerGroupByName(name string) (*ResponseComputerGroup, error) {
110110
endpoint := fmt.Sprintf("%s/name/%s", uriComputerGroups, name)
111111

112-
var group ComputerGroup
112+
var group ResponseComputerGroup
113113
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &group)
114114
if err != nil {
115115
return nil, fmt.Errorf("failed to fetch Computer Group by name: %v", err)
@@ -123,7 +123,7 @@ func (c *Client) GetComputerGroupByName(name string) (*ComputerGroup, error) {
123123
}
124124

125125
// CreateComputerGroup creates a new computer group.
126-
func (c *Client) CreateComputerGroup(group *ComputerGroupRequest) (*ComputerGroup, error) {
126+
func (c *Client) CreateComputerGroup(group *ResponseComputerGroup) (*ResponseComputerGroup, error) {
127127
endpoint := fmt.Sprintf("%s/id/0", uriComputerGroups) // Using ID 0 for creation as per the pattern
128128

129129
// Check if site is not provided and set default values
@@ -137,12 +137,12 @@ func (c *Client) CreateComputerGroup(group *ComputerGroupRequest) (*ComputerGrou
137137
// Wrap the group request with the desired XML name using an anonymous struct
138138
requestBody := struct {
139139
XMLName xml.Name `xml:"computer_group"`
140-
*ComputerGroupRequest
140+
*ResponseComputerGroup
141141
}{
142-
ComputerGroupRequest: group,
142+
ResponseComputerGroup: group,
143143
}
144144

145-
var createdGroup ComputerGroup
145+
var createdGroup ResponseComputerGroup
146146
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &createdGroup)
147147
if err != nil {
148148
return nil, fmt.Errorf("failed to create Computer Group: %v", err)
@@ -156,7 +156,7 @@ func (c *Client) CreateComputerGroup(group *ComputerGroupRequest) (*ComputerGrou
156156
}
157157

158158
// UpdateComputerGroupByID updates an existing computer group by its ID.
159-
func (c *Client) UpdateComputerGroupByID(id int, group *ComputerGroupRequest) (*ComputerGroup, error) {
159+
func (c *Client) UpdateComputerGroupByID(id int, group *ResponseComputerGroup) (*ResponseComputerGroup, error) {
160160
endpoint := fmt.Sprintf("%s/id/%d", uriComputerGroups, id)
161161

162162
// Check if site is not provided and set default values
@@ -170,12 +170,12 @@ func (c *Client) UpdateComputerGroupByID(id int, group *ComputerGroupRequest) (*
170170
// Wrap the group request with the desired XML name using an anonymous struct
171171
requestBody := struct {
172172
XMLName xml.Name `xml:"computer_group"`
173-
*ComputerGroupRequest
173+
*ResponseComputerGroup
174174
}{
175-
ComputerGroupRequest: group,
175+
ResponseComputerGroup: group,
176176
}
177177

178-
var updatedGroup ComputerGroup
178+
var updatedGroup ResponseComputerGroup
179179
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedGroup)
180180
if err != nil {
181181
return nil, fmt.Errorf("failed to update Computer Group by ID: %v", err)
@@ -189,7 +189,7 @@ func (c *Client) UpdateComputerGroupByID(id int, group *ComputerGroupRequest) (*
189189
}
190190

191191
// UpdateComputerGroupByName updates a computer group by its name.
192-
func (c *Client) UpdateComputerGroupByName(name string, group *ComputerGroupRequest) (*ComputerGroup, error) {
192+
func (c *Client) UpdateComputerGroupByName(name string, group *ResponseComputerGroup) (*ResponseComputerGroup, error) {
193193
endpoint := fmt.Sprintf("%s/name/%s", uriComputerGroups, name)
194194

195195
// Check if site is not provided and set default values
@@ -203,12 +203,12 @@ func (c *Client) UpdateComputerGroupByName(name string, group *ComputerGroupRequ
203203
// Wrap the group request with the desired XML name using an anonymous struct
204204
requestBody := struct {
205205
XMLName xml.Name `xml:"computer_group"`
206-
*ComputerGroupRequest
206+
*ResponseComputerGroup
207207
}{
208-
ComputerGroupRequest: group,
208+
ResponseComputerGroup: group,
209209
}
210210

211-
var updatedGroup ComputerGroup
211+
var updatedGroup ResponseComputerGroup
212212
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedGroup)
213213
if err != nil {
214214
return nil, fmt.Errorf("failed to update Computer Group by name: %v", err)

0 commit comments

Comments
 (0)