#![doc(alias = "channel.update")]
use super::*;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelUpdateV2 {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub broadcaster_user_id: types::UserId,
}
impl ChannelUpdateV2 {
pub fn broadcaster_user_id(broadcaster_user_id: impl Into<types::UserId>) -> Self {
Self {
broadcaster_user_id: broadcaster_user_id.into(),
}
}
}
impl EventSubscription for ChannelUpdateV2 {
type Payload = ChannelUpdateV2Payload;
const EVENT_TYPE: EventType = EventType::ChannelUpdate;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
const VERSION: &'static str = "2";
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelUpdateV2Payload {
pub broadcaster_user_id: types::UserId,
pub broadcaster_user_login: types::UserName,
pub broadcaster_user_name: types::DisplayName,
pub title: String,
pub language: String,
pub category_id: types::CategoryId,
pub category_name: String,
pub content_classification_labels: Vec<types::ContentClassificationId>,
}
#[deprecated(note = "Use `ChannelUpdateV2` instead")]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelUpdateV1 {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub broadcaster_user_id: types::UserId,
}
impl ChannelUpdateV1 {
pub fn broadcaster_user_id(broadcaster_user_id: impl Into<types::UserId>) -> Self {
Self {
broadcaster_user_id: broadcaster_user_id.into(),
}
}
}
impl EventSubscription for ChannelUpdateV1 {
type Payload = ChannelUpdateV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelUpdate;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
const VERSION: &'static str = "1";
}
#[deprecated(note = "Use `ChannelUpdateV2` instead")]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelUpdateV1Payload {
pub broadcaster_user_id: types::UserId,
pub broadcaster_user_login: types::UserName,
pub broadcaster_user_name: types::DisplayName,
pub title: String,
pub language: String,
pub category_id: types::CategoryId,
pub category_name: String,
pub is_mature: bool,
}
#[cfg(test)]
#[test]
fn parse_payload_v2() {
let payload = r#"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.update",
"version": "2",
"status": "enabled",
"cost": 0,
"condition": {
"broadcaster_user_id": "1337"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2023-06-29T17:20:33.860897266Z"
},
"event": {
"broadcaster_user_id": "1337",
"broadcaster_user_login": "cool_user",
"broadcaster_user_name": "Cool_User",
"title": "Best Stream Ever",
"language": "en",
"category_id": "12453",
"category_name": "Grand Theft Auto",
"content_classification_labels": [ "MatureGame" ]
}
}
"#;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}
#[cfg(test)]
#[test]
fn parse_payload_v1() {
let payload = r#"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.update",
"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": {
"broadcaster_user_id": "1337",
"broadcaster_user_login": "cool_user",
"broadcaster_user_name": "Cool_User",
"title": "Best Stream Ever",
"language": "en",
"category_id": "21779",
"category_name": "Fortnite",
"is_mature": false
}
}
"#;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}