tongbal_api/session/
builder.rs1use crate::{
2 BaseClient, Error, Response,
3 types::constants::{PAGE, SESSIONS, SIZE},
4};
5
6use super::SessionResponse;
7
8#[derive(Debug)]
9pub struct GetSession<'a, T> {
10 client: &'a T,
11 client_path: Option<&'static str>,
12 size: Option<u64>,
13 page: Option<&'a str>,
14}
15
16impl<'a, T> GetSession<'a, T>
17where
18 T: BaseClient,
19{
20 pub(crate) fn new(client: &'a T, client_path: Option<&'static str>) -> Self {
21 Self {
22 client,
23 client_path,
24 size: None,
25 page: None,
26 }
27 }
28
29 pub fn size(mut self, value: u64) -> Self {
30 self.size = Some(value);
31 self
32 }
33
34 pub fn page(mut self, value: &'a str) -> Self {
35 self.page = Some(value);
36 self
37 }
38
39 pub async fn send(self) -> Result<Response<SessionResponse>, Error> {
40 let mut url = self.client.base_url();
41
42 url.path_segments_mut().unwrap().push(SESSIONS);
43 if let Some(path) = self.client_path {
44 url.path_segments_mut().unwrap().push(path);
45 }
46
47 if let Some(size) = self.size {
48 url.query_pairs_mut().append_pair(SIZE, &size.to_string());
49 }
50 if let Some(page) = self.page {
51 url.query_pairs_mut().append_pair(PAGE, page);
52 }
53
54 crate::client::json(self.client.http_client().get(url)).await
55 }
56}