use crate::{
manage::billing::response::{Balance, Balances},
send_and_translate_response, Deepgram,
};
pub mod response;
#[derive(Debug, Clone)]
pub struct Billing<'a>(&'a Deepgram);
impl Deepgram {
pub fn billing(&self) -> Billing<'_> {
self.into()
}
}
impl<'a> From<&'a Deepgram> for Billing<'a> {
fn from(deepgram: &'a Deepgram) -> Self {
Self(deepgram)
}
}
impl Billing<'_> {
pub async fn list_balance(&self, project_id: &str) -> crate::Result<Balances> {
let url = format!("https://api.deepgram.com/v1/projects/{project_id}/balances",);
send_and_translate_response(self.0.client.get(url)).await
}
pub async fn get_balance(&self, project_id: &str, balance_id: &str) -> crate::Result<Balance> {
let url =
format!("https://api.deepgram.com/v1/projects/{project_id}/balances/{balance_id}",);
send_and_translate_response(self.0.client.get(url)).await
}
}
#[cfg(test)]
mod tests {
use crate::manage::billing::response::{Balance, BillingUnits};
#[test]
fn test() {
assert_eq!(
serde_json::from_str::<Balance>(
"{\"balance_id\":\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\",\"amount\":1,\"units\":\"usd\",\"purchase_order_id\":\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\"}",
).unwrap().units,
BillingUnits::Usd
);
}
}