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
#![doc(alias = "follow")]
#![doc(alias = "follows")]
use crate::{pubsub, types};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(into = "String", try_from = "String")]
pub struct Following {
pub channel_id: u32,
}
impl_de_ser!(
Following,
"following",
channel_id
);
impl pubsub::Topic for Following {
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
fn into_topic(self) -> pubsub::Topics { super::Topics::Following(self) }
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[serde(tag = "type")]
#[non_exhaustive]
pub struct FollowingReply {
pub display_name: types::DisplayName,
pub user_id: types::UserId,
pub username: types::UserName,
}
#[cfg(test)]
mod tests {
use super::super::{Response, TopicData};
use super::*;
#[test]
fn follow() {
let message = r##"
{
"display_name": "tmi",
"username": "tmi",
"user_id": "1234"
}
"##;
let source = format!(
r#"{{"type": "MESSAGE", "data": {{ "topic": "following.27620241", "message": {:?} }}}}"#,
message
);
let actual = dbg!(Response::parse(&source).unwrap());
assert!(matches!(
actual,
Response::Message {
data: TopicData::Following { .. },
}
));
}
#[test]
fn check_deser() {
use std::convert::TryInto as _;
let s = "following.1234";
assert_eq!(
Following { channel_id: 1234 },
s.to_string().try_into().unwrap()
);
}
#[test]
fn check_ser() {
let s = "following.1234";
let right: String = Following { channel_id: 1234 }.into();
assert_eq!(s.to_string(), right);
}
}