termii_rust/async_impl/rest/insights/
search.rs1use std::{collections::HashMap, sync::Arc};
4
5use crate::{
6 async_impl::http::client,
7 common::{errors, insights::search::SearchItem},
8};
9
10#[derive(Debug)]
11#[allow(dead_code)]
12pub struct Search<'a> {
13 api_key: &'a str,
14 client: Arc<client::HttpClient>,
15}
16
17impl<'a> Search<'a> {
18 pub(crate) fn new(api_key: &'a str, client: Arc<client::HttpClient>) -> Search<'a> {
19 Search { api_key, client }
20 }
21
22 pub async fn get(&self, phone_number: &str) -> Result<SearchItem, errors::HttpError> {
39 let mut params = HashMap::new();
40 params.insert("api_key", self.api_key);
41 params.insert("phone_number", phone_number);
42
43 let response = self.client.get("check/dnd", Some(params), None).await?;
44
45 let search_item = response_or_error_text_async!(response, SearchItem);
46
47 Ok(search_item)
48 }
49}