Skip to main content

hanzo_client/apis/
treasury_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_treasury`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetTreasuryError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_treasury_accounts`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetTreasuryAccountsError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Returns the reserve fund's health and the current revenue-share policy for any validated caller. It is a TRANSPARENCY view — a partner or author can see that the pool backing their payouts is solvent — and NOT per-org money, which is the customer's own commerce balance at /v1/billing/balance. The policy is read-only here; only a SuperAdmin sets it.
34pub async fn get_treasury(configuration: &configuration::Configuration, ) -> Result<models::TreasuryReport, Error<GetTreasuryError>> {
35
36    let uri_str = format!("{}/v1/treasury", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(ref token) = configuration.bearer_access_token {
43        req_builder = req_builder.bearer_auth(token.to_owned());
44    };
45
46    let req = req_builder.build()?;
47    let resp = configuration.client.execute(req).await?;
48
49    let status = resp.status();
50    let content_type = resp
51        .headers()
52        .get("content-type")
53        .and_then(|v| v.to_str().ok())
54        .unwrap_or("application/octet-stream");
55    let content_type = super::ContentType::from(content_type);
56
57    if !status.is_client_error() && !status.is_server_error() {
58        let content = resp.text().await?;
59        match content_type {
60            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
61            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TreasuryReport`"))),
62            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TreasuryReport`")))),
63        }
64    } else {
65        let content = resp.text().await?;
66        let entity: Option<GetTreasuryError> = serde_json::from_str(&content).ok();
67        Err(Error::ResponseError(ResponseContent { status, content, entity }))
68    }
69}
70
71/// Returns the ledger accounts the caller may see, with their balances. It is tenant-isolated SERVER-SIDE: an ordinary caller sees ONLY accounts under its own \"org:<tenant>:\" prefix, never house accounts and never another tenant's. A SuperAdmin may widen with ?scope=house (the reserve, revenue and payout house accounts) or ?org=<tenant> — the only way to cross the tenant boundary, and only for platform sudo. The answer is honestly empty until a tenant has ledger postings.
72pub async fn get_treasury_accounts(configuration: &configuration::Configuration, scope: Option<&str>, org: Option<&str>) -> Result<models::AccountsOut, Error<GetTreasuryAccountsError>> {
73    // add a prefix to parameters to efficiently prevent name collisions
74    let p_scope = scope;
75    let p_org = org;
76
77    let uri_str = format!("{}/v1/treasury/accounts", configuration.base_path);
78    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
79
80    if let Some(ref param_value) = p_scope {
81        req_builder = req_builder.query(&[("scope", &param_value.to_string())]);
82    }
83    if let Some(ref param_value) = p_org {
84        req_builder = req_builder.query(&[("org", &param_value.to_string())]);
85    }
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.bearer_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92
93    let req = req_builder.build()?;
94    let resp = configuration.client.execute(req).await?;
95
96    let status = resp.status();
97    let content_type = resp
98        .headers()
99        .get("content-type")
100        .and_then(|v| v.to_str().ok())
101        .unwrap_or("application/octet-stream");
102    let content_type = super::ContentType::from(content_type);
103
104    if !status.is_client_error() && !status.is_server_error() {
105        let content = resp.text().await?;
106        match content_type {
107            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccountsOut`"))),
109            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccountsOut`")))),
110        }
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<GetTreasuryAccountsError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
115    }
116}
117