1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetTransactionError {
22 Status401(models::Error401),
23 Status404(models::Error404),
24 Status405(models::Error405),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetTransactionIdRangeError {
32 Status400(models::Error400),
33 Status401(models::Error401),
34 Status404(models::Error404),
35 Status405(models::Error405),
36 Status416(models::Error416),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetTransactionsError {
44 Status400(models::Error400),
45 Status401(models::Error401),
46 Status403(models::Error403),
47 Status404(models::Error404),
48 Status405(models::Error405),
49 Status416(models::Error416),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetTransactionsSinceError {
57 Status400(models::Error400),
58 Status401(models::Error401),
59 Status404(models::Error404),
60 Status405(models::Error405),
61 Status416(models::Error416),
62 UnknownValue(serde_json::Value),
63}
64
65
66pub async fn get_transaction(configuration: &configuration::Configuration, account_id: &str, transaction_id: i32, accept_datetime_format: Option<models::DateTimeFormat>) -> Result<models::TransactionResponse, Error<GetTransactionError>> {
68 let p_account_id = account_id;
70 let p_transaction_id = transaction_id;
71 let p_accept_datetime_format = accept_datetime_format;
72
73 let uri_str = format!("{}/accounts/{accountId}/transactions/{transactionId}", configuration.base_path, accountId=crate::apis::urlencode(p_account_id), transactionId=p_transaction_id);
74 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
75
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(param_value) = p_accept_datetime_format {
80 req_builder = req_builder.header("Accept-Datetime-Format", param_value.to_string());
81 }
82 if let Some(ref token) = configuration.bearer_access_token {
83 req_builder = req_builder.bearer_auth(token.to_owned());
84 };
85
86 let req = req_builder.build()?;
87 let resp = configuration.client.execute(req).await?;
88
89 let status = resp.status();
90 let content_type = resp
91 .headers()
92 .get("content-type")
93 .and_then(|v| v.to_str().ok())
94 .unwrap_or("application/octet-stream");
95 let content_type = super::ContentType::from(content_type);
96
97 if !status.is_client_error() && !status.is_server_error() {
98 let content = resp.text().await?;
99 match content_type {
100 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransactionResponse`"))),
102 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::TransactionResponse`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<GetTransactionError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent { status, content, entity }))
108 }
109}
110
111pub async fn get_transaction_id_range(configuration: &configuration::Configuration, account_id: &str, from: i32, to: i32, accept_datetime_format: Option<models::DateTimeFormat>, r#type: Option<Vec<models::TransactionType>>) -> Result<models::TransactionIdRangeResponse, Error<GetTransactionIdRangeError>> {
113 let p_account_id = account_id;
115 let p_from = from;
116 let p_to = to;
117 let p_accept_datetime_format = accept_datetime_format;
118 let p_type = r#type;
119
120 let uri_str = format!("{}/accounts/{accountId}/transactions/idrange", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
121 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123 req_builder = req_builder.query(&[("from", &p_from.to_string())]);
124 req_builder = req_builder.query(&[("to", &p_to.to_string())]);
125 if let Some(ref param_value) = p_type {
126 req_builder = match "csv" {
127 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
128 _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
129 };
130 }
131 if let Some(ref user_agent) = configuration.user_agent {
132 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133 }
134 if let Some(param_value) = p_accept_datetime_format {
135 req_builder = req_builder.header("Accept-Datetime-Format", param_value.to_string());
136 }
137 if let Some(ref token) = configuration.bearer_access_token {
138 req_builder = req_builder.bearer_auth(token.to_owned());
139 };
140
141 let req = req_builder.build()?;
142 let resp = configuration.client.execute(req).await?;
143
144 let status = resp.status();
145 let content_type = resp
146 .headers()
147 .get("content-type")
148 .and_then(|v| v.to_str().ok())
149 .unwrap_or("application/octet-stream");
150 let content_type = super::ContentType::from(content_type);
151
152 if !status.is_client_error() && !status.is_server_error() {
153 let content = resp.text().await?;
154 match content_type {
155 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
156 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransactionIdRangeResponse`"))),
157 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::TransactionIdRangeResponse`")))),
158 }
159 } else {
160 let content = resp.text().await?;
161 let entity: Option<GetTransactionIdRangeError> = serde_json::from_str(&content).ok();
162 Err(Error::ResponseError(ResponseContent { status, content, entity }))
163 }
164}
165
166pub async fn get_transactions(configuration: &configuration::Configuration, account_id: &str, accept_datetime_format: Option<models::DateTimeFormat>, from: Option<&str>, to: Option<&str>, page_size: Option<i32>, r#type: Option<Vec<models::TransactionType>>) -> Result<models::TransactionsResponse, Error<GetTransactionsError>> {
168 let p_account_id = account_id;
170 let p_accept_datetime_format = accept_datetime_format;
171 let p_from = from;
172 let p_to = to;
173 let p_page_size = page_size;
174 let p_type = r#type;
175
176 let uri_str = format!("{}/accounts/{accountId}/transactions", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
177 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
178
179 if let Some(ref param_value) = p_from {
180 req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
181 }
182 if let Some(ref param_value) = p_to {
183 req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
184 }
185 if let Some(ref param_value) = p_page_size {
186 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
187 }
188 if let Some(ref param_value) = p_type {
189 req_builder = match "csv" {
190 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
191 _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
192 };
193 }
194 if let Some(ref user_agent) = configuration.user_agent {
195 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196 }
197 if let Some(param_value) = p_accept_datetime_format {
198 req_builder = req_builder.header("Accept-Datetime-Format", param_value.to_string());
199 }
200 if let Some(ref token) = configuration.bearer_access_token {
201 req_builder = req_builder.bearer_auth(token.to_owned());
202 };
203
204 let req = req_builder.build()?;
205 let resp = configuration.client.execute(req).await?;
206
207 let status = resp.status();
208 let content_type = resp
209 .headers()
210 .get("content-type")
211 .and_then(|v| v.to_str().ok())
212 .unwrap_or("application/octet-stream");
213 let content_type = super::ContentType::from(content_type);
214
215 if !status.is_client_error() && !status.is_server_error() {
216 let content = resp.text().await?;
217 match content_type {
218 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
219 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransactionsResponse`"))),
220 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::TransactionsResponse`")))),
221 }
222 } else {
223 let content = resp.text().await?;
224 let entity: Option<GetTransactionsError> = serde_json::from_str(&content).ok();
225 Err(Error::ResponseError(ResponseContent { status, content, entity }))
226 }
227}
228
229pub async fn get_transactions_since(configuration: &configuration::Configuration, account_id: &str, id: i32, accept_datetime_format: Option<models::DateTimeFormat>) -> Result<models::TransactionSinceIdResponse, Error<GetTransactionsSinceError>> {
231 let p_account_id = account_id;
233 let p_id = id;
234 let p_accept_datetime_format = accept_datetime_format;
235
236 let uri_str = format!("{}/accounts/{accountId}/transactions/sinceid", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
237 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
238
239 req_builder = req_builder.query(&[("id", &p_id.to_string())]);
240 if let Some(ref user_agent) = configuration.user_agent {
241 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
242 }
243 if let Some(param_value) = p_accept_datetime_format {
244 req_builder = req_builder.header("Accept-Datetime-Format", param_value.to_string());
245 }
246 if let Some(ref token) = configuration.bearer_access_token {
247 req_builder = req_builder.bearer_auth(token.to_owned());
248 };
249
250 let req = req_builder.build()?;
251 let resp = configuration.client.execute(req).await?;
252
253 let status = resp.status();
254 let content_type = resp
255 .headers()
256 .get("content-type")
257 .and_then(|v| v.to_str().ok())
258 .unwrap_or("application/octet-stream");
259 let content_type = super::ContentType::from(content_type);
260
261 if !status.is_client_error() && !status.is_server_error() {
262 let content = resp.text().await?;
263 match content_type {
264 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
265 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransactionSinceIdResponse`"))),
266 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::TransactionSinceIdResponse`")))),
267 }
268 } else {
269 let content = resp.text().await?;
270 let entity: Option<GetTransactionsSinceError> = serde_json::from_str(&content).ok();
271 Err(Error::ResponseError(ResponseContent { status, content, entity }))
272 }
273}
274