beeper_desktop_api/client/
search.rs1use crate::models::{SearchChatsOutput, SearchMessagesOutput};
4use crate::error::Result;
5use super::{BeeperClient, handle_response};
6
7impl BeeperClient {
8 pub async fn search_messages(
12 &self,
13 query: &str,
14 cursor: Option<&str>,
15 direction: Option<&str>,
16 ) -> Result<SearchMessagesOutput> {
17 let mut url = format!("{}/v1/messages/search?q={}", self.get_base_url(), urlencoding::encode(query));
18
19 if let Some(c) = cursor {
20 url.push_str(&format!("&cursor={}", urlencoding::encode(c)));
21 }
22
23 if let Some(d) = direction {
24 url.push_str(&format!("&direction={}", d));
25 }
26
27 let response = self
28 .get_http_client()
29 .get(&url)
30 .header("Authorization", self.get_auth_header())
31 .send()
32 .await?;
33
34 handle_response(response).await
35 }
36
37 pub async fn search_chats(
41 &self,
42 query: &str,
43 cursor: Option<&str>,
44 direction: Option<&str>,
45 ) -> Result<SearchChatsOutput> {
46 let mut url = format!("{}/v1/chats/search?q={}", self.get_base_url(), urlencoding::encode(query));
47
48 if let Some(c) = cursor {
49 url.push_str(&format!("&cursor={}", urlencoding::encode(c)));
50 }
51
52 if let Some(d) = direction {
53 url.push_str(&format!("&direction={}", d));
54 }
55
56 let response = self
57 .get_http_client()
58 .get(&url)
59 .header("Authorization", self.get_auth_header())
60 .send()
61 .await?;
62
63 handle_response(response).await
64 }
65}