kick_api/models/
followed_channel.rs1use serde::Deserialize;
2
3#[derive(Debug, Clone, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct FollowedChannelsResponse {
10 #[serde(default)]
12 pub next_cursor: Option<u64>,
13
14 #[serde(default)]
16 pub channels: Vec<FollowedChannel>,
17}
18
19#[derive(Debug, Clone, Deserialize)]
27pub struct FollowedChannel {
28 #[serde(default)]
30 pub is_live: bool,
31
32 #[serde(default)]
34 pub profile_picture: Option<String>,
35
36 #[serde(default)]
38 pub channel_slug: Option<String>,
39
40 #[serde(default)]
42 pub viewer_count: u64,
43
44 #[serde(default)]
46 pub category_name: Option<String>,
47
48 #[serde(default)]
50 pub user_username: Option<String>,
51
52 #[serde(default)]
54 pub session_title: Option<String>,
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_deserialize_followed_channels_response() {
63 let json = r##"{
64 "nextCursor": 5,
65 "channels": [
66 {
67 "is_live": true,
68 "profile_picture": "https://files.kick.com/images/user/57253/profile_image/thumb.webp",
69 "channel_slug": "knut",
70 "viewer_count": 151,
71 "category_name": "IRL",
72 "user_username": "Knut",
73 "session_title": "NPC Show + Iron World Fit Week expo"
74 },
75 {
76 "is_live": false,
77 "profile_picture": "https://files.kick.com/images/user/73899717/profile_image/thumb.webp",
78 "channel_slug": "anxstasia",
79 "viewer_count": 0,
80 "category_name": "",
81 "user_username": "anxstasia",
82 "session_title": null
83 }
84 ]
85 }"##;
86
87 let resp: FollowedChannelsResponse = serde_json::from_str(json).unwrap();
88
89 assert_eq!(resp.next_cursor, Some(5));
90 assert_eq!(resp.channels.len(), 2);
91
92 let ch = &resp.channels[0];
94 assert!(ch.is_live);
95 assert_eq!(ch.channel_slug, Some("knut".into()));
96 assert_eq!(ch.viewer_count, 151);
97 assert_eq!(ch.category_name, Some("IRL".into()));
98 assert_eq!(ch.user_username, Some("Knut".into()));
99 assert!(ch.session_title.is_some());
100 assert!(ch.profile_picture.is_some());
101
102 let ch2 = &resp.channels[1];
104 assert!(!ch2.is_live);
105 assert_eq!(ch2.channel_slug, Some("anxstasia".into()));
106 assert_eq!(ch2.viewer_count, 0);
107 assert!(ch2.session_title.is_none());
108 }
109
110 #[test]
111 fn test_deserialize_empty_followed_response() {
112 let json = r##"{"nextCursor": null, "channels": []}"##;
113 let resp: FollowedChannelsResponse = serde_json::from_str(json).unwrap();
114 assert!(resp.next_cursor.is_none());
115 assert!(resp.channels.is_empty());
116 }
117
118 #[test]
119 fn test_deserialize_minimal_followed_channel() {
120 let json = r##"{"channels": [{"is_live": false}]}"##;
121 let resp: FollowedChannelsResponse = serde_json::from_str(json).unwrap();
122 assert_eq!(resp.channels.len(), 1);
123 assert!(!resp.channels[0].is_live);
124 assert!(resp.channels[0].channel_slug.is_none());
125 assert_eq!(resp.channels[0].viewer_count, 0);
126 }
127}