Skip to main content

tongbal_api/restriction/
builder.rs

1use crate::{
2    BaseClient, Error, Response, UserClient,
3    types::constants::{NEXT, RESTRICT_CHANNELS, SIZE},
4};
5
6use super::RestrictionChannelResponse;
7
8#[derive(Debug)]
9pub struct GetRestriction<'a> {
10    client: &'a UserClient,
11    size: Option<u64>,
12    next: Option<String>,
13}
14
15impl<'a> GetRestriction<'a> {
16    pub(crate) fn new(client: &'a UserClient) -> Self {
17        Self {
18            client,
19            size: None,
20            next: None,
21        }
22    }
23
24    pub fn size(mut self, value: u64) -> Self {
25        self.size = Some(value);
26        self
27    }
28
29    pub fn next(mut self, value: impl Into<String>) -> Self {
30        self.next = Some(value.into());
31        self
32    }
33
34    pub async fn send(self) -> Result<Response<RestrictionChannelResponse>, Error> {
35        let mut url = self.client.base_url();
36
37        url.path_segments_mut().unwrap().push(RESTRICT_CHANNELS);
38
39        if let Some(size) = self.size {
40            url.query_pairs_mut().append_pair(SIZE, &size.to_string());
41        }
42        if let Some(next) = self.next {
43            url.query_pairs_mut().append_pair(NEXT, &next);
44        }
45
46        crate::client::json(self.client.http_client().get(url)).await
47    }
48}