use serde::Deserialize;
#[derive(Deserialize, Debug)]
#[must_use]
pub struct Balance {
balance: i64,
total_balance: i64,
currency: String,
spend_today: i64,
}
impl Balance {
#[must_use]
pub fn balance(&self) -> i64 {
self.balance
}
#[must_use]
pub fn total_balance(&self) -> i64 {
self.total_balance
}
#[must_use]
pub fn currency(&self) -> &String {
&self.currency
}
#[must_use]
pub fn spend_today(&self) -> i64 {
self.spend_today
}
}
pub use get::Request as Get;
mod get {
use super::Balance;
use crate::{endpoints::handle_response, Result};
pub struct Request<'a> {
reqwest_builder: reqwest::RequestBuilder,
account_id: &'a str,
}
impl<'a> Request<'a> {
pub(crate) fn new(
http_client: &reqwest::Client,
access_token: impl AsRef<str>,
account_id: &'a str,
) -> Self {
let reqwest_builder = http_client
.get("https://api.monzo.com/balance")
.bearer_auth(access_token.as_ref());
Self {
reqwest_builder,
account_id,
}
}
pub async fn send(self) -> Result<Balance> {
handle_response(
self.reqwest_builder
.query(&[("account_id", self.account_id)]),
)
.await
}
}
}