mastodon_api\methods\builders/
list.rs1use crate::MastodonClient;
2use crate::error::Result;
3use serde::de::DeserializeOwned;
4
5pub struct ListBuilder<'a, T> {
7 client: &'a MastodonClient,
8 url: String,
9 limit: Option<u32>,
10 since_id: Option<String>,
11 min_id: Option<String>,
12 max_id: Option<String>,
13 _marker: std::marker::PhantomData<T>,
14}
15
16impl<'a, T: DeserializeOwned> ListBuilder<'a, T> {
17 pub fn new(client: &'a MastodonClient, url: String) -> Self {
19 Self {
20 client,
21 url,
22 limit: None,
23 since_id: None,
24 min_id: None,
25 max_id: None,
26 _marker: std::marker::PhantomData,
27 }
28 }
29
30 pub fn limit(mut self, value: u32) -> Self {
32 self.limit = Some(value);
33 self
34 }
35
36 pub fn since_id(mut self, value: &str) -> Self {
38 self.since_id = Some(value.to_string());
39 self
40 }
41
42 pub fn min_id(mut self, value: &str) -> Self {
44 self.min_id = Some(value.to_string());
45 self
46 }
47
48 pub fn max_id(mut self, value: &str) -> Self {
50 self.max_id = Some(value.to_string());
51 self
52 }
53
54 pub async fn send(self) -> Result<Vec<T>> {
56 let mut req = self.client.http_client().get(&self.url);
57
58 if let Some(l) = self.limit {
59 req = req.query(&[("limit", l.to_string())]);
60 }
61 if let Some(s) = self.since_id {
62 req = req.query(&[("since_id", s)]);
63 }
64 if let Some(min) = self.min_id {
65 req = req.query(&[("min_id", min)]);
66 }
67 if let Some(max) = self.max_id {
68 req = req.query(&[("max_id", max)]);
69 }
70
71 self.client.send(req).await
72 }
73}