termii_rust/async_impl/rest/insights/
balance.rs

1//! Retrieve your org's wallet balance via API.
2
3use std::{collections::HashMap, sync::Arc};
4
5use crate::{
6    async_impl::http::client,
7    common::{errors, insights::balance::BalanceItem},
8};
9
10#[derive(Debug)]
11#[allow(dead_code)]
12pub struct Balance<'a> {
13    api_key: &'a str,
14    client: Arc<client::HttpClient>,
15}
16
17impl<'a> Balance<'a> {
18    pub(crate) fn new(api_key: &'a str, client: Arc<client::HttpClient>) -> Balance<'a> {
19        Balance { api_key, client }
20    }
21
22    /// Gets your account balance.
23    ///
24    /// ## Examples
25    ///
26    /// ```rust
27    /// use termii_rust::{
28    ///     async_impl::rest::termii,
29    ///     common::insights::balance::BalanceItem,
30    /// }
31    ///
32    /// let client = termii::Termii::new("Your API key");
33    ///
34    /// let balance = client.insights.balance.get().await.unwrap();
35    ///
36    /// println!("{:?}", balance);
37    /// ```
38    pub async fn get(&self) -> Result<BalanceItem, errors::HttpError> {
39        let mut params = HashMap::new();
40        params.insert("api_key", self.api_key);
41
42        let response = self.client.get("get-balance", Some(params), None).await?;
43
44        let balance_item = response_or_error_text_async!(response, BalanceItem);
45
46        Ok(balance_item)
47    }
48}