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 ChannelRaidV1 {
#[builder(default, setter(into))]
pub from_broadcaster_user_id: Option<types::UserId>,
#[builder(default, setter(into))]
pub to_broadcaster_user_id: Option<types::UserId>,
}
impl EventSubscription for ChannelRaidV1 {
type Payload = ChannelRaidV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelRaid;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] =
&[twitch_oauth2::Scope::ChannelReadSubscriptions];
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 ChannelRaidV1Payload {
pub from_broadcaster_user_id: types::UserId,
pub from_broadcaster_user_login: types::UserName,
pub from_broadcaster_user_name: types::DisplayName,
pub to_broadcaster_user_id: types::UserId,
pub to_broadcaster_user_login: types::UserName,
pub to_broadcaster_user_name: types::DisplayName,
pub viewers: i64,
}
#[cfg(test)]
#[test]
fn parse_payload() {
let payload = r#"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.raid",
"version": "1",
"status": "enabled",
"cost": 0,
"condition": {
"to_broadcaster_user_id": "1337"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2019-11-16T10:11:12.123Z"
},
"event": {
"from_broadcaster_user_id": "1234",
"from_broadcaster_user_login": "cool_user",
"from_broadcaster_user_name": "Cool_User",
"to_broadcaster_user_id": "1337",
"to_broadcaster_user_login": "cooler_user",
"to_broadcaster_user_name": "Cooler_User",
"viewers": 9001
}
}
"#;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}