tongbal_api/channel/
mod.rs1mod builder;
2mod response;
3mod types;
4
5pub use tongbal_types::Tier;
6
7pub use builder::{GetChannelFollower, GetChannelSubscriber};
8pub use response::{ChannelResponse, FollowersResponse, ModeratorResponse, SubscribersResponse};
9pub use types::{Channel, Follower, Moderator, Sort, Subscriber, UserRole};
10
11use std::future::Future;
12
13use crate::{
14 AppClient, BaseClient, Error, Response, UserClient,
15 types::{
16 ChannelId,
17 constants::{CHANNELIDS, CHANNELS},
18 },
19};
20
21pub trait UserChannelAPI: BaseClient {
22 fn get_channel_moderators(
24 &self,
25 ) -> impl Future<Output = Result<Response<ModeratorResponse>, Error>> + Send;
26
27 fn get_channel_followers<'a>(&'a self) -> GetChannelFollower<'a>;
29
30 fn get_channel_subscribers<'a>(&'a self) -> GetChannelSubscriber<'a>;
32}
33
34pub trait AppChannelAPI: BaseClient {
35 fn get_channels(
37 &self,
38 channel_ids: &[ChannelId],
39 ) -> impl Future<Output = Result<Response<ChannelResponse>, Error>> + Send;
40}
41
42impl AppChannelAPI for AppClient {
43 async fn get_channels(
44 &self,
45 channel_ids: &[ChannelId],
46 ) -> Result<Response<ChannelResponse>, Error> {
47 let mut url = self.base_url();
48
49 url.path_segments_mut().unwrap().push(CHANNELS);
50
51 url.query_pairs_mut()
52 .extend_pairs(channel_ids.iter().map(|id| (CHANNELIDS, id)));
53
54 crate::client::json(self.http_client().get(url)).await
55 }
56}
57
58impl UserChannelAPI for UserClient {
59 async fn get_channel_moderators(&self) -> Result<Response<ModeratorResponse>, Error> {
60 let mut url = self.base_url();
61
62 url.path_segments_mut()
63 .unwrap()
64 .extend([CHANNELS, "streaming-roles"]);
65
66 crate::client::json(self.http_client().get(url)).await
67 }
68
69 fn get_channel_followers<'a>(&'a self) -> GetChannelFollower<'a> {
70 GetChannelFollower::new(self)
71 }
72
73 fn get_channel_subscribers<'a>(&'a self) -> GetChannelSubscriber<'a> {
74 GetChannelSubscriber::new(self)
75 }
76}