-
Notifications
You must be signed in to change notification settings - Fork 6
/
volumePurchasingSubscriptions.go
80 lines (63 loc) · 2.82 KB
/
volumePurchasingSubscriptions.go
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
75
76
77
78
79
80
// volumePurchasingSubscriptions.go
// Jamf Pro Api
package jamfpro
import (
"fmt"
)
const uriVolumePurchasingSubscriptions = "/api/v1/volume-purchasing-subscriptions"
type ResponseVolumePurchasingSubscription struct {
TotalCount int `json:"totalCount"`
Results []VolumePurchasingSubscription `json:"results"`
}
type VolumePurchasingSubscription struct {
Name string `json:"name"` // Required
Enabled bool `json:"enabled,omitempty"`
Triggers []string `json:"triggers,omitempty"`
LocationIds []string `json:"locationIds,omitempty"`
InternalRecipients []InternalRecipient `json:"internalRecipients,omitempty"`
ExternalRecipients []ExternalRecipient `json:"externalRecipients,omitempty"`
SiteId string `json:"siteId,omitempty"`
ID string `json:"id,omitempty"`
}
type InternalRecipient struct {
AccountId string `json:"accountId"` // Required
Frequency string `json:"frequency,omitempty"`
}
type ExternalRecipient struct {
Name string `json:"name"` // Required
Email string `json:"email"` // Required
}
// GetVolumePurchasingSubscriptionByID retrieves the Volume Purchasing Subscription by its ID
func (c *Client) GetVolumePurchasingSubscriptionByID(id int) (*ResponseVolumePurchasingSubscription, error) {
url := fmt.Sprintf("%s/%d", uriVolumePurchasingSubscriptions, id)
var subscription ResponseVolumePurchasingSubscription
if err := c.DoRequest("GET", url, nil, nil, &subscription); err != nil {
return nil, fmt.Errorf("failed to execute request: %v", err)
}
return &subscription, nil
}
// GetVolumePurchasingSubscriptions retrieves all Volume Purchasing Subscriptions
func (c *Client) GetVolumePurchasingSubscriptions() (*ResponseVolumePurchasingSubscription, error) {
url := uriVolumePurchasingSubscriptions
var subscriptions ResponseVolumePurchasingSubscription
if err := c.DoRequest("GET", url, nil, nil, &subscriptions); err != nil {
return nil, fmt.Errorf("failed to fetch all Volume Purchasing Subscriptions: %v", err)
}
return &subscriptions, nil
}
// CreateVolumePurchasingSubscription creates a new Volume Purchasing Subscription
func (c *Client) CreateVolumePurchasingSubscription(subscription *VolumePurchasingSubscription) (*ResponseVolumePurchasingSubscription, error) {
url := uriVolumePurchasingSubscriptions
// Construct the request body
reqBody := &struct {
*VolumePurchasingSubscription
}{
VolumePurchasingSubscription: subscription,
}
// Execute the request
var responseSubscription ResponseVolumePurchasingSubscription
if err := c.DoRequestDebug("POST", url, reqBody, nil, &responseSubscription); err != nil {
return nil, fmt.Errorf("failed to create Volume Purchasing Subscription: %v", err)
}
return &responseSubscription, nil
}