1use crate::Client;
2use crate::ClientResult;
3
4pub struct Search {
5 pub client: Client,
6}
7
8impl Search {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Search { client }
12 }
13
14 pub async fn message(
32 &self,
33 count: i64,
34 highlight: bool,
35 page: i64,
36 query: &str,
37 sort: &str,
38 sort_dir: &str,
39 ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
40 let mut query_args: Vec<(String, String)> = Default::default();
41 if count > 0 {
42 query_args.push(("count".to_string(), count.to_string()));
43 }
44 if highlight {
45 query_args.push(("highlight".to_string(), highlight.to_string()));
46 }
47 if page > 0 {
48 query_args.push(("page".to_string(), page.to_string()));
49 }
50 if !query.is_empty() {
51 query_args.push(("query".to_string(), query.to_string()));
52 }
53 if !sort.is_empty() {
54 query_args.push(("sort".to_string(), sort.to_string()));
55 }
56 if !sort_dir.is_empty() {
57 query_args.push(("sort_dir".to_string(), sort_dir.to_string()));
58 }
59 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
60 let url = self
61 .client
62 .url(&format!("/search.messages?{}", query_), None);
63 self.client
64 .get(
65 &url,
66 crate::Message {
67 body: None,
68 content_type: None,
69 },
70 )
71 .await
72 }
73}