termii_rust/async_impl/rest/insights/
history.rs1use std::{collections::HashMap, sync::Arc};
4
5use async_trait::async_trait;
6
7use crate::{
8 async_impl::http::client,
9 common::{
10 errors,
11 insights::history::{HistoryItem, HistoryResponse},
12 pagination,
13 },
14};
15
16#[derive(Debug)]
17#[allow(dead_code)]
18pub struct History<'a> {
19 api_key: &'a str,
20 client: Arc<client::HttpClient>,
21}
22
23impl<'a> History<'a> {
24 pub(crate) fn new(api_key: &'a str, client: Arc<client::HttpClient>) -> History<'a> {
25 History { api_key, client }
26 }
27
28 pub(crate) async fn _get(&self, page: &str) -> Result<Vec<HistoryItem>, errors::HttpError> {
29 let mut params = HashMap::new();
30 params.insert("api_key", self.api_key);
31 params.insert("page", page);
32
33 let response = self.client.get("sms/inbox", Some(params), None).await?;
34
35 let history_item = response_or_error_text_async!(response, HistoryResponse);
36
37 Ok(history_item.data.data)
38 }
39
40 pub async fn get(&self, page: Option<&str>) -> Result<Vec<HistoryItem>, errors::HttpError> {
62 let page = page.unwrap_or("1");
63 let history_items = self._get(page).await?;
64 Ok(history_items)
65 }
66}
67
68#[async_trait]
69impl pagination::PaginatedResourceAsync for History<'_> {
70 type Item = HistoryItem;
71
72 async fn _get(&self, page: &str) -> Result<Vec<Self::Item>, errors::HttpError> {
73 History::_get(self, page).await
74 }
75}