bitwarden_api_api/apis/
accounts_billing_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AccountsBillingHistoryGetError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum AccountsBillingInvoicesGetError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum AccountsBillingPaymentMethodGetError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum AccountsBillingPreviewInvoicePostError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum AccountsBillingTransactionsGetError {
49 UnknownValue(serde_json::Value),
50}
51
52pub async fn accounts_billing_history_get(
53 configuration: &configuration::Configuration,
54) -> Result<models::BillingHistoryResponseModel, Error<AccountsBillingHistoryGetError>> {
55 let uri_str = format!("{}/accounts/billing/history", configuration.base_path);
56 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
57
58 if let Some(ref user_agent) = configuration.user_agent {
59 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60 }
61 if let Some(ref token) = configuration.oauth_access_token {
62 req_builder = req_builder.bearer_auth(token.to_owned());
63 };
64
65 let req = req_builder.build()?;
66 let resp = configuration.client.execute(req).await?;
67
68 let status = resp.status();
69 let content_type = resp
70 .headers()
71 .get("content-type")
72 .and_then(|v| v.to_str().ok())
73 .unwrap_or("application/octet-stream");
74 let content_type = super::ContentType::from(content_type);
75
76 if !status.is_client_error() && !status.is_server_error() {
77 let content = resp.text().await?;
78 match content_type {
79 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
80 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BillingHistoryResponseModel`"))),
81 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::BillingHistoryResponseModel`")))),
82 }
83 } else {
84 let content = resp.text().await?;
85 let entity: Option<AccountsBillingHistoryGetError> = serde_json::from_str(&content).ok();
86 Err(Error::ResponseError(ResponseContent {
87 status,
88 content,
89 entity,
90 }))
91 }
92}
93
94pub async fn accounts_billing_invoices_get(
95 configuration: &configuration::Configuration,
96 status: Option<&str>,
97 start_after: Option<&str>,
98) -> Result<(), Error<AccountsBillingInvoicesGetError>> {
99 let p_status = status;
101 let p_start_after = start_after;
102
103 let uri_str = format!("{}/accounts/billing/invoices", configuration.base_path);
104 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106 if let Some(ref param_value) = p_status {
107 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
108 }
109 if let Some(ref param_value) = p_start_after {
110 req_builder = req_builder.query(&[("startAfter", ¶m_value.to_string())]);
111 }
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref token) = configuration.oauth_access_token {
116 req_builder = req_builder.bearer_auth(token.to_owned());
117 };
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123
124 if !status.is_client_error() && !status.is_server_error() {
125 Ok(())
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<AccountsBillingInvoicesGetError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent {
130 status,
131 content,
132 entity,
133 }))
134 }
135}
136
137pub async fn accounts_billing_payment_method_get(
138 configuration: &configuration::Configuration,
139) -> Result<models::BillingPaymentResponseModel, Error<AccountsBillingPaymentMethodGetError>> {
140 let uri_str = format!(
141 "{}/accounts/billing/payment-method",
142 configuration.base_path
143 );
144 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
145
146 if let Some(ref user_agent) = configuration.user_agent {
147 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148 }
149 if let Some(ref token) = configuration.oauth_access_token {
150 req_builder = req_builder.bearer_auth(token.to_owned());
151 };
152
153 let req = req_builder.build()?;
154 let resp = configuration.client.execute(req).await?;
155
156 let status = resp.status();
157 let content_type = resp
158 .headers()
159 .get("content-type")
160 .and_then(|v| v.to_str().ok())
161 .unwrap_or("application/octet-stream");
162 let content_type = super::ContentType::from(content_type);
163
164 if !status.is_client_error() && !status.is_server_error() {
165 let content = resp.text().await?;
166 match content_type {
167 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BillingPaymentResponseModel`"))),
169 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::BillingPaymentResponseModel`")))),
170 }
171 } else {
172 let content = resp.text().await?;
173 let entity: Option<AccountsBillingPaymentMethodGetError> =
174 serde_json::from_str(&content).ok();
175 Err(Error::ResponseError(ResponseContent {
176 status,
177 content,
178 entity,
179 }))
180 }
181}
182
183pub async fn accounts_billing_preview_invoice_post(
184 configuration: &configuration::Configuration,
185 preview_individual_invoice_request_body: Option<models::PreviewIndividualInvoiceRequestBody>,
186) -> Result<(), Error<AccountsBillingPreviewInvoicePostError>> {
187 let p_preview_individual_invoice_request_body = preview_individual_invoice_request_body;
189
190 let uri_str = format!(
191 "{}/accounts/billing/preview-invoice",
192 configuration.base_path
193 );
194 let mut req_builder = configuration
195 .client
196 .request(reqwest::Method::POST, &uri_str);
197
198 if let Some(ref user_agent) = configuration.user_agent {
199 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
200 }
201 if let Some(ref token) = configuration.oauth_access_token {
202 req_builder = req_builder.bearer_auth(token.to_owned());
203 };
204 req_builder = req_builder.json(&p_preview_individual_invoice_request_body);
205
206 let req = req_builder.build()?;
207 let resp = configuration.client.execute(req).await?;
208
209 let status = resp.status();
210
211 if !status.is_client_error() && !status.is_server_error() {
212 Ok(())
213 } else {
214 let content = resp.text().await?;
215 let entity: Option<AccountsBillingPreviewInvoicePostError> =
216 serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent {
218 status,
219 content,
220 entity,
221 }))
222 }
223}
224
225pub async fn accounts_billing_transactions_get(
226 configuration: &configuration::Configuration,
227 start_after: Option<String>,
228) -> Result<(), Error<AccountsBillingTransactionsGetError>> {
229 let p_start_after = start_after;
231
232 let uri_str = format!("{}/accounts/billing/transactions", configuration.base_path);
233 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
234
235 if let Some(ref param_value) = p_start_after {
236 req_builder = req_builder.query(&[("startAfter", ¶m_value.to_string())]);
237 }
238 if let Some(ref user_agent) = configuration.user_agent {
239 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240 }
241 if let Some(ref token) = configuration.oauth_access_token {
242 req_builder = req_builder.bearer_auth(token.to_owned());
243 };
244
245 let req = req_builder.build()?;
246 let resp = configuration.client.execute(req).await?;
247
248 let status = resp.status();
249
250 if !status.is_client_error() && !status.is_server_error() {
251 Ok(())
252 } else {
253 let content = resp.text().await?;
254 let entity: Option<AccountsBillingTransactionsGetError> =
255 serde_json::from_str(&content).ok();
256 Err(Error::ResponseError(ResponseContent {
257 status,
258 content,
259 entity,
260 }))
261 }
262}