bitwarden_api_api/apis/
accounts_billing_api.rs1use 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::{AuthRequired, 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 async fn get_billing_history(&self) -> Result<models::BillingHistoryResponseModel, Error>;
31
32 async fn get_invoices<'a>(
34 &self,
35 status: Option<&'a str>,
36 start_after: Option<&'a str>,
37 ) -> Result<(), Error>;
38
39 async fn get_transactions<'a>(&self, start_after: Option<String>) -> Result<(), Error>;
41}
42
43pub struct AccountsBillingApiClient {
44 configuration: Arc<configuration::Configuration>,
45}
46
47impl AccountsBillingApiClient {
48 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
49 Self { configuration }
50 }
51}
52
53#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
54#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
55impl AccountsBillingApi for AccountsBillingApiClient {
56 async fn get_billing_history(&self) -> Result<models::BillingHistoryResponseModel, Error> {
57 let local_var_configuration = &self.configuration;
58
59 let local_var_client = &local_var_configuration.client;
60
61 let local_var_uri_str = format!(
62 "{}/accounts/billing/history",
63 local_var_configuration.base_path
64 );
65 let mut local_var_req_builder =
66 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
67
68 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
69
70 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
71 }
72
73 async fn get_invoices<'a>(
74 &self,
75 status: Option<&'a str>,
76 start_after: Option<&'a str>,
77 ) -> Result<(), Error> {
78 let local_var_configuration = &self.configuration;
79
80 let local_var_client = &local_var_configuration.client;
81
82 let local_var_uri_str = format!(
83 "{}/accounts/billing/invoices",
84 local_var_configuration.base_path
85 );
86 let mut local_var_req_builder =
87 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
88
89 if let Some(ref param_value) = status {
90 local_var_req_builder =
91 local_var_req_builder.query(&[("status", ¶m_value.to_string())]);
92 }
93 if let Some(ref param_value) = start_after {
94 local_var_req_builder =
95 local_var_req_builder.query(&[("startAfter", ¶m_value.to_string())]);
96 }
97 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
98
99 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
100 }
101
102 async fn get_transactions<'a>(&self, start_after: Option<String>) -> Result<(), Error> {
103 let local_var_configuration = &self.configuration;
104
105 let local_var_client = &local_var_configuration.client;
106
107 let local_var_uri_str = format!(
108 "{}/accounts/billing/transactions",
109 local_var_configuration.base_path
110 );
111 let mut local_var_req_builder =
112 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
113
114 if let Some(ref param_value) = start_after {
115 local_var_req_builder =
116 local_var_req_builder.query(&[("startAfter", ¶m_value.to_string())]);
117 }
118 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
119
120 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
121 }
122}