twilio_rust_openapi/apis/
api20100401_balance_api.rs

1/*
2 * Twilio - Api
3 *
4 * This is the public Twilio REST API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: support@twilio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`fetch_balance`]
18#[derive(Clone, Debug)]
19pub struct FetchBalanceParams {
20    /// The unique SID identifier of the Account.
21    pub account_sid: String
22}
23
24
25/// struct for typed errors of method [`fetch_balance`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum FetchBalanceError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Fetch the balance for an Account based on Account Sid. Balance changes may not be reflected immediately. Child accounts do not contain balance information
34pub async fn fetch_balance(configuration: &configuration::Configuration, params: FetchBalanceParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodBalance, Error<FetchBalanceError>> {
35    let local_var_configuration = configuration;
36
37    // unbox the parameters
38    let account_sid = params.account_sid;
39
40
41    let local_var_client = &local_var_configuration.client;
42
43    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Balance.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
44    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
45
46    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
47        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
48    }
49    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
50        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
51    };
52
53    let local_var_req = local_var_req_builder.build()?;
54    let local_var_resp = local_var_client.execute(local_var_req).await?;
55
56    let local_var_status = local_var_resp.status();
57    let local_var_content = local_var_resp.text().await?;
58
59    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
60        serde_json::from_str(&local_var_content).map_err(Error::from)
61    } else {
62        let local_var_entity: Option<FetchBalanceError> = serde_json::from_str(&local_var_content).ok();
63        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
64        Err(Error::ResponseError(local_var_error))
65    }
66}
67