mastodon_api\methods/
markers.rs1use crate::MastodonClient;
2use crate::error::Result;
3use crate::models::Marker;
4use std::collections::HashMap;
5
6pub struct MarkersHandler<'a> {
8 client: &'a MastodonClient,
9}
10
11impl<'a> MarkersHandler<'a> {
12 pub fn new(client: &'a MastodonClient) -> Self {
14 Self { client }
15 }
16
17 pub async fn get(&self, timelines: &[&str]) -> Result<HashMap<String, Marker>> {
27 let url = format!("{}/api/v1/markers", self.client.base_url());
28 let mut req = self.client.http_client().get(&url);
29 for timeline in timelines {
30 req = req.query(&[("timeline[]", timeline)]);
31 }
32 self.client.send(req).await
33 }
34
35 pub async fn update(&self, timeline: &str, last_read_id: &str) -> Result<Marker> {
46 let url = format!("{}/api/v1/markers", self.client.base_url());
47 let mut params = HashMap::new();
48 let mut inner_params = HashMap::new();
49 inner_params.insert("last_read_id", last_read_id);
50 params.insert(timeline, inner_params);
51
52 let req = self.client.http_client().post(&url).form(¶ms);
53 let results: HashMap<String, Marker> = self.client.send(req).await?;
54 results
55 .get(timeline)
56 .cloned()
57 .ok_or_else(|| crate::error::MastodonError::ApiError {
58 status: reqwest::StatusCode::OK,
59 message: format!("Marker for {} not returned", timeline),
60 })
61 }
62}