termii_rust/async_impl/rest/insights/
search.rs

1//! The search API verifies and detects a phonenumber's DND status.
2
3use 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    /// Verify a phone number.
23    ///
24    /// ## Examples
25    ///
26    /// ```rust
27    /// use termii_rust::{
28    ///     async_impl::rest::termii,
29    ///     common::insights::search::SearchItem,
30    /// }
31    ///
32    /// let client = termii::Termii::new("Your API key");
33    ///
34    /// let search:SearchItem = client.insights.search.get("234XXXXXXXXXX").await.unwrap();
35    ///
36    /// println!("{:?}", search);
37    /// ```
38    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}