termii_rust/async_impl/rest/insights/
status.rs

1//! The status API detects fake or ported phone numbers.
2
3use std::{collections::HashMap, sync::Arc};
4
5use crate::{
6    async_impl::http::client,
7    common::{errors, insights::status::StatusItem},
8};
9
10#[derive(Debug)]
11pub struct Status<'a> {
12    api_key: &'a str,
13    client: Arc<client::HttpClient>,
14}
15
16impl<'a> Status<'a> {
17    pub(crate) fn new(api_key: &'a str, client: Arc<client::HttpClient>) -> Status<'a> {
18        Status { api_key, client }
19    }
20
21    /// Detects fake or ported numbers.
22    ///
23    /// ## Examples
24    ///
25    /// ```rust
26    /// use termii_rust::{
27    ///     async_impl::rest::termii,
28    ///     common::insights::status::StatusItem,
29    /// }
30    ///
31    /// let client = termii::Termii::new("Your API key");
32    ///
33    /// let status:StatusItem = client.insights.status.get("234XXXXXXXXXX", "NG").await.unwrap();
34    ///
35    /// println!("{:?}", status);
36    /// ```
37    pub async fn get(
38        &self,
39        phone_number: &str,
40        country_code: &str,
41    ) -> Result<StatusItem, errors::HttpError> {
42        let mut params = HashMap::new();
43        params.insert("api_key", self.api_key);
44        params.insert("phone_number", phone_number);
45        params.insert("country_code", country_code);
46
47        let response = self
48            .client
49            .get("insight/number/query", Some(params), None)
50            .await?;
51
52        let status_response = response_or_error_text_async!(response, StatusItem);
53
54        Ok(status_response)
55    }
56}