bitwarden_api_api/apis/
accounts_billing_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait AccountsBillingApi: Send + Sync {
29    /// GET /accounts/billing/history
30    async fn get_billing_history(
31        &self,
32    ) -> Result<models::BillingHistoryResponseModel, Error<GetBillingHistoryError>>;
33
34    /// GET /accounts/billing/invoices
35    async fn get_invoices<'a>(
36        &self,
37        status: Option<&'a str>,
38        start_after: Option<&'a str>,
39    ) -> Result<(), Error<GetInvoicesError>>;
40
41    /// GET /accounts/billing/transactions
42    async fn get_transactions<'a>(
43        &self,
44        start_after: Option<String>,
45    ) -> Result<(), Error<GetTransactionsError>>;
46}
47
48pub struct AccountsBillingApiClient {
49    configuration: Arc<configuration::Configuration>,
50}
51
52impl AccountsBillingApiClient {
53    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
54        Self { configuration }
55    }
56}
57
58#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
59#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
60impl AccountsBillingApi for AccountsBillingApiClient {
61    async fn get_billing_history(
62        &self,
63    ) -> Result<models::BillingHistoryResponseModel, Error<GetBillingHistoryError>> {
64        let local_var_configuration = &self.configuration;
65
66        let local_var_client = &local_var_configuration.client;
67
68        let local_var_uri_str = format!(
69            "{}/accounts/billing/history",
70            local_var_configuration.base_path
71        );
72        let mut local_var_req_builder =
73            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
74
75        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
76            local_var_req_builder = local_var_req_builder
77                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78        }
79        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
80            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
81        };
82
83        let local_var_req = local_var_req_builder.build()?;
84        let local_var_resp = local_var_client.execute(local_var_req).await?;
85
86        let local_var_status = local_var_resp.status();
87        let local_var_content_type = local_var_resp
88            .headers()
89            .get("content-type")
90            .and_then(|v| v.to_str().ok())
91            .unwrap_or("application/octet-stream");
92        let local_var_content_type = super::ContentType::from(local_var_content_type);
93        let local_var_content = local_var_resp.text().await?;
94
95        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96            match local_var_content_type {
97                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
98                ContentType::Text => {
99                    return Err(Error::from(serde_json::Error::custom(
100                        "Received `text/plain` content type response that cannot be converted to `models::BillingHistoryResponseModel`",
101                    )));
102                }
103                ContentType::Unsupported(local_var_unknown_type) => {
104                    return Err(Error::from(serde_json::Error::custom(format!(
105                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BillingHistoryResponseModel`"
106                    ))));
107                }
108            }
109        } else {
110            let local_var_entity: Option<GetBillingHistoryError> =
111                serde_json::from_str(&local_var_content).ok();
112            let local_var_error = ResponseContent {
113                status: local_var_status,
114                content: local_var_content,
115                entity: local_var_entity,
116            };
117            Err(Error::ResponseError(local_var_error))
118        }
119    }
120
121    async fn get_invoices<'a>(
122        &self,
123        status: Option<&'a str>,
124        start_after: Option<&'a str>,
125    ) -> Result<(), Error<GetInvoicesError>> {
126        let local_var_configuration = &self.configuration;
127
128        let local_var_client = &local_var_configuration.client;
129
130        let local_var_uri_str = format!(
131            "{}/accounts/billing/invoices",
132            local_var_configuration.base_path
133        );
134        let mut local_var_req_builder =
135            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
136
137        if let Some(ref param_value) = status {
138            local_var_req_builder =
139                local_var_req_builder.query(&[("status", &param_value.to_string())]);
140        }
141        if let Some(ref param_value) = start_after {
142            local_var_req_builder =
143                local_var_req_builder.query(&[("startAfter", &param_value.to_string())]);
144        }
145        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146            local_var_req_builder = local_var_req_builder
147                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148        }
149        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
150            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
151        };
152
153        let local_var_req = local_var_req_builder.build()?;
154        let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156        let local_var_status = local_var_resp.status();
157        let local_var_content = local_var_resp.text().await?;
158
159        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
160            Ok(())
161        } else {
162            let local_var_entity: Option<GetInvoicesError> =
163                serde_json::from_str(&local_var_content).ok();
164            let local_var_error = ResponseContent {
165                status: local_var_status,
166                content: local_var_content,
167                entity: local_var_entity,
168            };
169            Err(Error::ResponseError(local_var_error))
170        }
171    }
172
173    async fn get_transactions<'a>(
174        &self,
175        start_after: Option<String>,
176    ) -> Result<(), Error<GetTransactionsError>> {
177        let local_var_configuration = &self.configuration;
178
179        let local_var_client = &local_var_configuration.client;
180
181        let local_var_uri_str = format!(
182            "{}/accounts/billing/transactions",
183            local_var_configuration.base_path
184        );
185        let mut local_var_req_builder =
186            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
187
188        if let Some(ref param_value) = start_after {
189            local_var_req_builder =
190                local_var_req_builder.query(&[("startAfter", &param_value.to_string())]);
191        }
192        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193            local_var_req_builder = local_var_req_builder
194                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
195        }
196        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
197            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
198        };
199
200        let local_var_req = local_var_req_builder.build()?;
201        let local_var_resp = local_var_client.execute(local_var_req).await?;
202
203        let local_var_status = local_var_resp.status();
204        let local_var_content = local_var_resp.text().await?;
205
206        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
207            Ok(())
208        } else {
209            let local_var_entity: Option<GetTransactionsError> =
210                serde_json::from_str(&local_var_content).ok();
211            let local_var_error = ResponseContent {
212                status: local_var_status,
213                content: local_var_content,
214                entity: local_var_entity,
215            };
216            Err(Error::ResponseError(local_var_error))
217        }
218    }
219}
220
221/// struct for typed errors of method [`AccountsBillingApi::get_billing_history`]
222#[derive(Debug, Clone, Serialize, Deserialize)]
223#[serde(untagged)]
224pub enum GetBillingHistoryError {
225    UnknownValue(serde_json::Value),
226}
227/// struct for typed errors of method [`AccountsBillingApi::get_invoices`]
228#[derive(Debug, Clone, Serialize, Deserialize)]
229#[serde(untagged)]
230pub enum GetInvoicesError {
231    UnknownValue(serde_json::Value),
232}
233/// struct for typed errors of method [`AccountsBillingApi::get_transactions`]
234#[derive(Debug, Clone, Serialize, Deserialize)]
235#[serde(untagged)]
236pub enum GetTransactionsError {
237    UnknownValue(serde_json::Value),
238}