-
Notifications
You must be signed in to change notification settings - Fork 88
/
polls.go
114 lines (96 loc) · 3.91 KB
/
polls.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
package helix
type Poll struct {
ID string `json:"id"`
BroadcasterID string `json:"broadcaster_id"`
BroadcasterLogin string `json:"broadcaster_login"`
BroadcasterName string `json:"broadcaster_name"`
Title string `json:"title"`
Choices []PollChoice `json:"choices"`
BitsVotingEnabled bool `json:"bits_voting_enabled"`
BitsPerVote int `json:"bits_per_vote"`
ChannelPointsVotingEnabled bool `json:"channel_points_voting_enabled"`
ChannelPointsPerVote int `json:"channel_points_per_vote"`
Status string `json:"status"`
Duration int `json:"duration"`
StartedAt Time `json:"started_at"`
EndedAt Time `json:"ended_at"`
}
type PollChoice struct {
ID string `json:"id"`
Title string `json:"title"`
BitsVotes int `json:"bits_votes"`
ChannelPointsVotes int `json:"channel_points_votes"`
Votes int `json:"votes"`
}
type ManyPolls struct {
Polls []Poll `json:"data"`
Pagination Pagination `json:"pagination"`
}
type PollsResponse struct {
ResponseCommon
Data ManyPolls
}
type PollsParams struct {
BroadcasterID string `query:"broadcaster_id"`
ID string `query:"id"`
After string `query:"after"`
First string `query:"first"`
}
type GetPollsResponse struct {
ResponseCommon
Data ManyPolls
}
// Required scope: channel:read:polls
func (c *Client) GetPolls(params *PollsParams) (*PollsResponse, error) {
resp, err := c.get("/polls", &ManyPolls{}, params)
if err != nil {
return nil, err
}
polls := &PollsResponse{}
resp.HydrateResponseCommon(&polls.ResponseCommon)
polls.Data.Polls = resp.Data.(*ManyPolls).Polls
polls.Data.Pagination = resp.Data.(*ManyPolls).Pagination
return polls, nil
}
type CreatePollParams struct {
BroadcasterID string `json:"broadcaster_id"`
Title string `json:"title"` // Maximum: 60 characters.
Choices []PollChoiceParam `json:"choices"` // Minimum: 2 choices. Maximum: 5 choices.
Duration int `json:"duration"` // Minimum: 15. Maximum: 1800.
BitsVotingEnabled bool `json:"bits_voting_enabled"` // Default: false
BitsPerVote int `json:"bits_per_vote"` // Minimum: 0. Maximum: 10000.
ChannelPointsVotingEnabled bool `json:"channel_points_voting_enabled"` // Default: false
ChannelPointsPerVote int `json:"channel_points_per_vote"` // Minimum: 0. Maximum: 1000000.
}
type PollChoiceParam struct {
Title string `json:"title"` // Maximum: 25 characters.
}
// Required scope: channel:manage:polls
func (c *Client) CreatePoll(params *CreatePollParams) (*PollsResponse, error) {
resp, err := c.postAsJSON("/polls", &ManyPolls{}, params)
if err != nil {
return nil, err
}
polls := &PollsResponse{}
resp.HydrateResponseCommon(&polls.ResponseCommon)
polls.Data.Polls = resp.Data.(*ManyPolls).Polls
polls.Data.Pagination = resp.Data.(*ManyPolls).Pagination
return polls, nil
}
type EndPollParams struct {
BroadcasterID string `json:"broadcaster_id"`
ID string `json:"id"`
Status string `json:"status"`
}
// Required scope: channel:manage:polls
func (c *Client) EndPoll(params *EndPollParams) (*PollsResponse, error) {
resp, err := c.patchAsJSON("/polls", &ManyPolls{}, params)
if err != nil {
return nil, err
}
polls := &PollsResponse{}
resp.HydrateResponseCommon(&polls.ResponseCommon)
polls.Data.Polls = resp.Data.(*ManyPolls).Polls
polls.Data.Pagination = resp.Data.(*ManyPolls).Pagination
return polls, nil
}