Skip to main content

tongbal_api/channel/
builder.rs

1use crate::{
2    BaseClient, Error, Response, UserClient,
3    types::constants::{CHANNELS, FOLLOWERS, PAGE, SIZE, SORT, SUBSCRIBERS},
4};
5
6use super::{FollowersResponse, Sort, SubscribersResponse};
7
8pub struct GetChannelFollower<'a> {
9    client: &'a UserClient,
10    page: Option<u64>,
11    size: Option<u64>,
12}
13
14impl<'a> GetChannelFollower<'a> {
15    pub(crate) fn new(client: &'a UserClient) -> Self {
16        Self {
17            client,
18            page: None,
19            size: None,
20        }
21    }
22
23    pub fn page(mut self, value: u64) -> Self {
24        self.page = Some(value);
25        self
26    }
27
28    pub fn size(mut self, value: u64) -> Self {
29        self.size = Some(value);
30        self
31    }
32
33    pub async fn send(self) -> Result<Response<FollowersResponse>, Error> {
34        let mut url = self.client.base_url();
35
36        url.path_segments_mut()
37            .unwrap()
38            .extend([CHANNELS, FOLLOWERS]);
39
40        if let Some(page) = self.page {
41            url.query_pairs_mut().append_pair(PAGE, &page.to_string());
42        }
43        if let Some(size) = self.size {
44            url.query_pairs_mut().append_pair(SIZE, &size.to_string());
45        }
46
47        crate::client::json(self.client.http_client().get(url)).await
48    }
49}
50
51pub struct GetChannelSubscriber<'a> {
52    client: &'a UserClient,
53    page: Option<u64>,
54    size: Option<u64>,
55    sort: Option<Sort>,
56}
57
58impl<'a> GetChannelSubscriber<'a> {
59    pub(crate) fn new(client: &'a UserClient) -> Self {
60        Self {
61            client,
62            page: None,
63            size: None,
64            sort: None,
65        }
66    }
67
68    pub fn page(mut self, value: u64) -> Self {
69        self.page = Some(value);
70        self
71    }
72
73    pub fn size(mut self, value: u64) -> Self {
74        self.size = Some(value);
75        self
76    }
77
78    pub fn sort(mut self, value: Sort) -> Self {
79        self.sort = Some(value);
80        self
81    }
82
83    pub async fn send(self) -> Result<Response<SubscribersResponse>, Error> {
84        let mut url = self.client.base_url();
85
86        url.path_segments_mut()
87            .unwrap()
88            .extend([CHANNELS, SUBSCRIBERS]);
89
90        if let Some(page) = self.page {
91            url.query_pairs_mut().append_pair(PAGE, &page.to_string());
92        }
93        if let Some(size) = self.size {
94            url.query_pairs_mut().append_pair(SIZE, &size.to_string());
95        }
96        if let Some(sort) = self.sort {
97            url.query_pairs_mut().append_pair(SORT, sort.as_str());
98        }
99
100        crate::client::json(self.client.http_client().get(url)).await
101    }
102}