twitch_api/eventsub/channel/
unban.rs

1#![doc(alias = "channel.unban")]
2//! A viewer is unbanned from the specified channel.
3use super::*;
4
5/// [`channel.unban`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelunban): a viewer is unbanned from the specified channel.
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
8#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
9#[non_exhaustive]
10pub struct ChannelUnbanV1 {
11    /// The broadcaster user ID for the channel you want to get unban notifications for.
12    #[cfg_attr(feature = "typed-builder", builder(setter(into)))]
13    pub broadcaster_user_id: types::UserId,
14}
15
16impl ChannelUnbanV1 {
17    /// The broadcaster user ID for the channel you want to get unban notifications for.
18    pub fn broadcaster_user_id(broadcaster_user_id: impl Into<types::UserId>) -> Self {
19        Self {
20            broadcaster_user_id: broadcaster_user_id.into(),
21        }
22    }
23}
24
25impl EventSubscription for ChannelUnbanV1 {
26    type Payload = ChannelUnbanV1Payload;
27
28    const EVENT_TYPE: EventType = EventType::ChannelUnban;
29    #[cfg(feature = "twitch_oauth2")]
30    const SCOPE: twitch_oauth2::Validator =
31        twitch_oauth2::validator![twitch_oauth2::Scope::ChannelModerate];
32    const VERSION: &'static str = "1";
33}
34
35/// [`channel.unban`](ChannelUnbanV1) response payload.
36#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
37#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
38#[non_exhaustive]
39pub struct ChannelUnbanV1Payload {
40    /// The requested broadcaster ID.
41    pub broadcaster_user_id: types::UserId,
42    /// The requested broadcaster login.
43    pub broadcaster_user_login: types::UserName,
44    /// The requested broadcaster display name.
45    pub broadcaster_user_name: types::DisplayName,
46    /// The user id for the user who was unbanned on the specified channel.
47    pub user_id: types::UserId,
48    /// The user login for the user who was unbanned on the specified channel.
49    pub user_login: types::UserName,
50    /// The user display name for the user who was unbanned on the specified channel.
51    pub user_name: types::DisplayName,
52    /// The user ID of the issuer of the unban.
53    pub moderator_user_id: types::UserId,
54    /// The user login of the issuer of the unban.
55    pub moderator_user_login: types::UserName,
56    /// The user name of the issuer of the unban.
57    pub moderator_user_name: types::DisplayName,
58}
59
60#[cfg(test)]
61#[test]
62fn parse_payload() {
63    let payload = r#"
64    {
65        "subscription": {
66            "id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
67            "type": "channel.unban",
68            "version": "1",
69            "status": "enabled",
70            "cost": 0,
71            "condition": {
72                "broadcaster_user_id": "1337"
73            },
74             "transport": {
75                "method": "webhook",
76                "callback": "https://example.com/webhooks/callback"
77            },
78            "created_at": "2019-11-16T10:11:12.123Z"
79        },
80        "event": {
81            "user_id": "1234",
82            "user_login": "cool_user",
83            "user_name": "Cool_User",
84            "broadcaster_user_id": "1337",
85            "broadcaster_user_login": "cooler_user",
86            "broadcaster_user_name": "Cooler_User",
87            "moderator_user_id": "1339",
88            "moderator_user_login": "mod_user",
89            "moderator_user_name": "Mod_User"
90        }
91    }
92    "#;
93
94    let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
95    crate::tests::roundtrip(&val)
96}