-
Notifications
You must be signed in to change notification settings - Fork 6
/
drm_policies.go
85 lines (72 loc) · 3.16 KB
/
drm_policies.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
81
82
83
84
85
package jwplatform
import (
"fmt"
"net/http"
"github.com/google/go-querystring/query"
)
// DRMPolicyResource is the resource that is returned for all DRM Policy resource requests
type DRMPolicyResource struct {
V2ResourceResponse
Metadata DRMPolicyMetadata `json:"metadata"`
}
// DRMPolicyWriteRequest is the request structure required for DRMPolicy create and update calls.
type DRMPolicyWriteRequest struct {
Metadata DRMPolicyMetadata `json:"metadata"`
}
// DRMPolicyMetadata describes a DRMPolicy resource
type DRMPolicyMetadata struct {
Name string `json:"name"`
MaxWidth int `json:"max_width"`
WidevineSecurity string `json:"widevine_security"`
PlayreadySecurity int `json:"playready_security"`
AllowOfflinePersistence bool `json:"allow_offline_persistence"`
DigitalOutputProtection string `json:"digital_output_protection"`
LicenseDuration int `json:"license_duration"`
PlaybackDuration int `json:"playback_duration"`
}
// DRMPolicyResourcesResponse is the response structure for DRMPolicy list calls.
type DRMPolicyResourcesResponse struct {
V2ResourcesResponse
DRMPolicies []DRMPolicyResource `json:"drm_policies"`
}
// DRMPoliciesClient for interacting with V2 DRM Policies API.
type DRMPoliciesClient struct {
v2Client *V2Client
}
// Get a single DRMPolicy resource by ID.
func (c *DRMPoliciesClient) Get(siteID, drmPolicyID string) (*DRMPolicyResource, error) {
drmPolicy := &DRMPolicyResource{}
path := fmt.Sprintf("/v2/sites/%s/drm_policies/%s", siteID, drmPolicyID)
err := c.v2Client.Request(http.MethodGet, path, drmPolicy, nil, nil)
return drmPolicy, err
}
// Create a DRMPolicy resource.
func (c *DRMPoliciesClient) Create(siteID string, DRMPolicyMetadata *DRMPolicyMetadata) (*DRMPolicyResource, error) {
createRequestData := &DRMPolicyWriteRequest{Metadata: *DRMPolicyMetadata}
drmPolicy := &DRMPolicyResource{}
path := fmt.Sprintf("/v2/sites/%s/drm_policies", siteID)
err := c.v2Client.Request(http.MethodPost, path, drmPolicy, createRequestData, nil)
return drmPolicy, err
}
// List all DRMPolicy resources.
func (c *DRMPoliciesClient) List(siteID string, queryParams *QueryParams) (*DRMPolicyResourcesResponse, error) {
drmPolicies := &DRMPolicyResourcesResponse{}
path := fmt.Sprintf("/v2/sites/%s/drm_policies", siteID)
urlValues, _ := query.Values(queryParams)
err := c.v2Client.Request(http.MethodGet, path, drmPolicies, nil, urlValues)
return drmPolicies, err
}
// Update a DRMPolicy resource by ID.
func (c *DRMPoliciesClient) Update(siteID, drmPolicyID string, DRMPolicyMetadata *DRMPolicyMetadata) (*DRMPolicyResource, error) {
updateRequestData := &DRMPolicyWriteRequest{Metadata: *DRMPolicyMetadata}
drmPolicy := &DRMPolicyResource{}
path := fmt.Sprintf("/v2/sites/%s/drm_policies/%s", siteID, drmPolicyID)
err := c.v2Client.Request(http.MethodPatch, path, drmPolicy, updateRequestData, nil)
return drmPolicy, err
}
// Delete a DRMPolicy resource by ID.
func (c *DRMPoliciesClient) Delete(siteID, drmPolicyID string) error {
path := fmt.Sprintf("/v2/sites/%s/drm_policies/%s", siteID, drmPolicyID)
err := c.v2Client.Request(http.MethodDelete, path, nil, nil, nil)
return err
}