-
Notifications
You must be signed in to change notification settings - Fork 88
/
schedule.go
187 lines (151 loc) · 5.56 KB
/
schedule.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package helix
// GetScheduleParams are the parameters for GetSchedule
type GetScheduleParams struct {
BroadcasterID string `query:"broadcaster_id"`
ID string `query:"id"`
StartTime Time `query:"start_time"`
UTCOffset string `query:"utc_offset"`
First int `query:"first"`
After string `query:"after"`
}
// GetScheduleResponse is the response data in GetSchedule
type GetScheduleResponse struct {
ResponseCommon
Data GetScheduleData
}
type GetScheduleData struct {
Schedule ScheduleData `json:"data"`
Pagination GetSchedulePagination `json:"pagination"`
}
type ScheduleData struct {
Segments []GetScheduleSegment `json:"segments"`
BroadcasterID string `json:"broadcaster_id"`
BroadcasterName string `json:"broadcaster_name"`
BroadcasterLogin string `json:"broadcaster_login"`
Vacation GetScheduleVacation `json:"vacation"`
}
type GetScheduleSegment struct {
ID string `json:"id"`
StartTime Time `json:"start_time"`
EndTime Time `json:"end_time"`
Title string `json:"title"`
CanceledUntil string `json:"canceled_until"`
Category GetScheduleSegmentCategory `json:"category"`
IsRecurring bool `json:"is_recurring"`
}
type GetScheduleSegmentCategory struct {
ID string `json:"id"`
Name string `json:"name"`
}
type GetScheduleVacation struct {
StartTime Time `json:"start_time"`
EndTime Time `json:"end_time"`
}
type GetSchedulePagination struct {
Cursor string `json:"cursor"`
}
// Gets the broadcaster’s streaming schedule.
// You can get the entire schedule or specific segments of the schedule
func (c *Client) GetSchedule(params *GetScheduleParams) (*GetScheduleResponse, error) {
resp, err := c.get("/schedule", &GetScheduleData{}, params)
if err != nil {
return nil, err
}
schedule := &GetScheduleResponse{}
resp.HydrateResponseCommon(&schedule.ResponseCommon)
schedule.Data.Schedule = resp.Data.(*GetScheduleData).Schedule
schedule.Data.Pagination = resp.Data.(*GetScheduleData).Pagination
return schedule, nil
}
type UpdateScheduleParams struct {
BroadcasterID string `json:"broadcaster_id"`
IsVacationEnabled bool `json:"is_vacation_enabled"`
VacationStartTime Time `json:"vacation_start_time"`
VacationEndTime Time `json:"vacation_end_time"`
Timezone string `json:"timezone"`
}
type UpdateScheduleResponse struct {
ResponseCommon
}
// Updates the broadcaster’s schedule settings, such as scheduling a vacation
func (c *Client) UpdateSchedule(params *UpdateScheduleParams) (*UpdateScheduleResponse, error) {
resp, err := c.get("/schedule/settings", nil, params)
if err != nil {
return nil, err
}
schedule := &UpdateScheduleResponse{}
resp.HydrateResponseCommon(&schedule.ResponseCommon)
return schedule, nil
}
type CreateScheduleSegmentParams struct {
BroadcasterID string `json:"broadcaster_id"`
StartTime Time `json:"start_time"`
Timezone string `json:"timezone"`
Duration string `json:"duration"`
IsRecurring bool `json:"is_recurring"`
CategoryID string `json:"category_id"`
Title string `json:"title"`
}
type CreateScheduleSegmentResponse struct {
ResponseCommon
Data CreateScheduleSegmentData
}
type CreateScheduleSegmentData struct {
Schedule ScheduleData `json:"data"`
}
// Updates the broadcaster’s schedule settings, such as scheduling a vacation
func (c *Client) CreateScheduleSegment(params *CreateScheduleSegmentParams) (*CreateScheduleSegmentResponse, error) {
resp, err := c.post("/schedule/segment", &CreateScheduleSegmentData{}, params)
if err != nil {
return nil, err
}
schedule := &CreateScheduleSegmentResponse{}
resp.HydrateResponseCommon(&schedule.ResponseCommon)
schedule.Data.Schedule = resp.Data.(*CreateScheduleSegmentData).Schedule
return schedule, nil
}
type UpdateScheduleSegmentParams struct {
BroadcasterID string `json:"broadcaster_id"`
ID string `json:"id"`
StartTime Time `json:"start_time"`
Duration string `json:"duration"`
CategoryID string `json:"category_id"`
Title string `json:"title"`
IsCanceled bool `json:"is_canceled"`
Timezone string `json:"timezone"`
}
type UpdateScheduleSegmentResponse struct {
ResponseCommon
Data UpdateScheduleSegmentData
}
type UpdateScheduleSegmentData struct {
Schedule ScheduleData `json:"data"`
}
// Updates the broadcaster’s schedule settings, such as scheduling a vacation
func (c *Client) UpdateScheduleSegment(params *UpdateScheduleSegmentParams) (*UpdateScheduleSegmentResponse, error) {
resp, err := c.patchAsJSON("/schedule/segment", &UpdateScheduleSegmentData{}, params)
if err != nil {
return nil, err
}
schedule := &UpdateScheduleSegmentResponse{}
resp.HydrateResponseCommon(&schedule.ResponseCommon)
schedule.Data.Schedule = resp.Data.(*UpdateScheduleSegmentData).Schedule
return schedule, nil
}
type DeleteScheduleSegmentParams struct {
BroadcasterID string `json:"broadcaster_id"`
ID string `json:"id"`
}
type DeleteScheduleSegmentResponse struct {
ResponseCommon
}
// Removes a broadcast segment from the broadcaster’s streaming schedule
func (c *Client) DeleteScheduleSegment(params *DeleteScheduleSegmentParams) (*DeleteScheduleSegmentResponse, error) {
resp, err := c.delete("/schedule/segment", nil, params)
if err != nil {
return nil, err
}
schedule := &DeleteScheduleSegmentResponse{}
resp.HydrateResponseCommon(&schedule.ResponseCommon)
return schedule, nil
}