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
#![doc(alias = "channel.poll.begin")]
use super::*;
#[derive(Clone, Debug, typed_builder::TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelPollBeginV1 {
#[builder(setter(into))]
pub broadcaster_user_id: types::UserId,
}
impl EventSubscription for ChannelPollBeginV1 {
type Payload = ChannelPollBeginV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelPollBegin;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::ChannelReadPolls];
const VERSION: &'static str = "1";
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelPollBeginV1Payload {
pub bits_voting: BitsVoting,
pub broadcaster_user_id: types::UserId,
pub broadcaster_user_login: types::UserName,
pub broadcaster_user_name: types::DisplayName,
pub channel_points_voting: ChannelPointsVoting,
pub choices: Vec<types::PollChoice>,
pub ends_at: types::Timestamp,
pub id: types::PollId,
pub started_at: types::Timestamp,
pub title: String,
}
#[cfg(test)]
#[test]
fn parse_payload() {
let payload = r##"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.poll.begin",
"version": "1",
"status": "enabled",
"cost": 0,
"condition": {
"broadcaster_user_id": "1337"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2019-11-16T10:11:12.123Z"
},
"event": {
"id": "1243456",
"broadcaster_user_id": "1337",
"broadcaster_user_login": "cool_user",
"broadcaster_user_name": "Cool_User",
"title": "Aren’t shoes just really hard socks?",
"choices": [
{"id": "123", "title": "Yeah!"},
{"id": "124", "title": "No!"},
{"id": "125", "title": "Maybe!"}
],
"bits_voting": {
"is_enabled": true,
"amount_per_vote": 10
},
"channel_points_voting": {
"is_enabled": true,
"amount_per_vote": 10
},
"started_at": "2020-07-15T17:16:03.17106713Z",
"ends_at": "2020-07-15T17:16:08.17106713Z"
}
}
"##;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}