-
Notifications
You must be signed in to change notification settings - Fork 88
/
user_extensions.go
112 lines (93 loc) · 3.82 KB
/
user_extensions.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package helix
type UserExtension struct {
CanActivate bool `json:"can_activate"`
ID string `json:"id"`
Name string `json:"name"`
Type []string `json:"type"`
Version string `json:"version"`
}
type ManyUserExtensions struct {
UserExtensions []UserExtension `json:"data"`
}
type UserExtensionsResponse struct {
ResponseCommon
Data ManyUserExtensions
}
// GetUserExtensions gets a list of all extensions (both active and inactive) for a specified user,
// identified by a Bearer token
//
// Required scope: user:read:broadcast
func (c *Client) GetUserExtensions() (*UserExtensionsResponse, error) {
resp, err := c.get("/users/extensions/list", &ManyUserExtensions{}, nil)
if err != nil {
return nil, err
}
userExtensions := &UserExtensionsResponse{}
resp.HydrateResponseCommon(&userExtensions.ResponseCommon)
userExtensions.Data.UserExtensions = resp.Data.(*ManyUserExtensions).UserExtensions
return userExtensions, nil
}
type UserActiveExtensionInfo struct {
Active bool `json:"active"`
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
X int `json:"x"`
Y int `json:"y"`
}
type UserActiveExtension struct {
Component map[string]UserActiveExtensionInfo `json:"component"`
Overlay map[string]UserActiveExtensionInfo `json:"overlay"`
Panel map[string]UserActiveExtensionInfo `json:"panel"`
}
type UserActiveExtensionSet struct {
UserActiveExtensions UserActiveExtension `json:"data"`
}
type UserActiveExtensionsResponse struct {
ResponseCommon
Data UserActiveExtensionSet
}
type UserActiveExtensionsParams struct {
UserID string `query:"user_id"` // Optional, limit 1
}
// GetUserActiveExtensions Gets information about active extensions installed by a specified user, identified
// by a user ID or Bearer token.
//
// Optional scope: user:read:broadcast or user:edit:broadcast
func (c *Client) GetUserActiveExtensions(params *UserActiveExtensionsParams) (*UserActiveExtensionsResponse, error) {
resp, err := c.get("/users/extensions", &UserActiveExtensionSet{}, params)
if err != nil {
return nil, err
}
userActiveExtensions := &UserActiveExtensionsResponse{}
resp.HydrateResponseCommon(&userActiveExtensions.ResponseCommon)
userActiveExtensions.Data.UserActiveExtensions = resp.Data.(*UserActiveExtensionSet).UserActiveExtensions
return userActiveExtensions, nil
}
type UpdateUserExtensionsPayload struct {
Component map[string]UserActiveExtensionInfo `json:"component,omitempty"`
Overlay map[string]UserActiveExtensionInfo `json:"overlay,omitempty"`
Panel map[string]UserActiveExtensionInfo `json:"panel,omitempty"`
}
type wrappedUpdateUserExtensionsPayload struct {
UpdateUserExtensionsPayload `json:"data"`
}
// UpdateUserExtensions Updates the activation state, extension ID, and/or version number of installed extensions for a specified user, identified by a Bearer token.
// If you try to activate a given extension under multiple extension types, the last write wins (and there is no guarantee of write order).
//
// Required scope: user:edit:broadcast
func (c *Client) UpdateUserExtensions(payload *UpdateUserExtensionsPayload) (*UserActiveExtensionsResponse, error) {
normalizedPayload := &wrappedUpdateUserExtensionsPayload{UpdateUserExtensionsPayload: *payload}
resp, err := c.putAsJSON("/users/extensions", &UserActiveExtensionSet{}, normalizedPayload)
if err != nil {
return nil, err
}
userActiveExtensions := &UserActiveExtensionsResponse{}
userActiveExtensions.StatusCode = resp.StatusCode
userActiveExtensions.Header = resp.Header
userActiveExtensions.Error = resp.Error
userActiveExtensions.ErrorStatus = resp.ErrorStatus
userActiveExtensions.ErrorMessage = resp.ErrorMessage
userActiveExtensions.Data.UserActiveExtensions = resp.Data.(*UserActiveExtensionSet).UserActiveExtensions
return userActiveExtensions, nil
}