-
Notifications
You must be signed in to change notification settings - Fork 89
/
extension_configuration.go
121 lines (96 loc) · 4.02 KB
/
extension_configuration.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
113
114
115
116
117
118
119
120
121
package helix
import "fmt"
// SegmentType A segment configuration type
type ExtensionSegmentType string
// Types of segments datastores for the configuration service
const (
ExtensionConfigrationBroadcasterSegment ExtensionSegmentType = "broadcaster"
ExtensionConfigurationDeveloperSegment ExtensionSegmentType = "developer"
ExtensionConfigurationGlobalSegment ExtensionSegmentType = "global"
)
func (s ExtensionSegmentType) String() string {
return string(s)
}
type ExtensionSetConfigurationParams struct {
Segment ExtensionSegmentType `json:"segment"`
ExtensionID string `json:"extension_id"`
// BroadcasterID is only populated if segment is of type 'developer' || 'broadcaster'
BroadcasterID string `json:"broadcaster_id,omitempty"`
Version string `json:"version"`
Content string `json:"content"`
}
type ExtensionConfigurationSegment struct {
Segment ExtensionSegmentType `json:"segment"`
Version string `json:"version"`
Content string `json:"content"`
}
type ExtensionGetConfigurationParams struct {
ExtensionID string `query:"extension_id"`
BroadcasterID string `query:"broadcaster_id"`
Segments []ExtensionSegmentType `query:"segment"`
}
type ExtensionSetRequiredConfigurationParams struct {
BroadcasterID string `query:"broadcaster_id" json:"-"`
ExtensionID string `json:"extension_id"`
RequiredConfiguration string `json:"required_version"`
ExtensionVersion string `json:"extension_version"`
ConfigurationVersion string `json:"configuration_version"`
}
type ExtensionSetRequiredConfigurationResponse struct {
ResponseCommon
}
type ExtensionGetConfigurationSegmentResponse struct {
ResponseCommon
Data ManyExtensionConfigurationSegments
}
type ManyExtensionConfigurationSegments struct {
Segments []ExtensionConfigurationSegment `json:"data"`
}
type ExtensionSetConfigurationResponse struct {
ResponseCommon
}
// https://dev.twitch.tv/docs/extensions/reference/#set-extension-configuration-segment
func (c *Client) SetExtensionSegmentConfig(params *ExtensionSetConfigurationParams) (*ExtensionSetConfigurationResponse, error) {
if params.BroadcasterID != "" {
switch params.Segment {
case ExtensionConfigurationDeveloperSegment, ExtensionConfigrationBroadcasterSegment:
default:
return nil, fmt.Errorf("error: developer or broadcaster extension configuration segment type must be provided for broadcasters")
}
}
resp, err := c.putAsJSON("/extensions/configurations", &ManyPolls{}, params)
if err != nil {
return nil, err
}
setExtCnfgResp := &ExtensionSetConfigurationResponse{}
resp.HydrateResponseCommon(&setExtCnfgResp.ResponseCommon)
return setExtCnfgResp, nil
}
func (c *Client) GetExtensionConfigurationSegment(params *ExtensionGetConfigurationParams) (*ExtensionGetConfigurationSegmentResponse, error) {
if params.BroadcasterID != "" {
for _, segment := range params.Segments {
switch segment {
case ExtensionConfigurationDeveloperSegment, ExtensionConfigrationBroadcasterSegment:
default:
return nil, fmt.Errorf("error: only developer or broadcaster extension configuration segment type must be provided for broadcasters")
}
}
}
resp, err := c.get("/extensions/configurations", &ManyExtensionConfigurationSegments{}, params)
if err != nil {
return nil, err
}
extCfgSegResp := &ExtensionGetConfigurationSegmentResponse{}
resp.HydrateResponseCommon(&extCfgSegResp.ResponseCommon)
extCfgSegResp.Data.Segments = resp.Data.(*ManyExtensionConfigurationSegments).Segments
return extCfgSegResp, nil
}
func (c *Client) SetExtensionRequiredConfiguration(params *ExtensionSetRequiredConfigurationParams) (*ExtensionSetRequiredConfigurationResponse, error) {
resp, err := c.putAsJSON("/extensions/configurations/required_configuration", &ExtensionSetRequiredConfigurationResponse{}, params)
if err != nil {
return nil, err
}
extReqCfgResp := &ExtensionSetRequiredConfigurationResponse{}
resp.HydrateResponseCommon(&extReqCfgResp.ResponseCommon)
return extReqCfgResp, nil
}