amazon_spapi/apis/
accounts_api.rs1use 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 GetAccountError {
22 Status400(models::seller_wallet_2024_03_01::ErrorList),
23 Status403(models::seller_wallet_2024_03_01::ErrorList),
24 Status404(models::seller_wallet_2024_03_01::ErrorList),
25 Status408(models::seller_wallet_2024_03_01::ErrorList),
26 Status413(models::seller_wallet_2024_03_01::ErrorList),
27 Status415(models::seller_wallet_2024_03_01::ErrorList),
28 Status429(models::seller_wallet_2024_03_01::ErrorList),
29 Status500(models::seller_wallet_2024_03_01::ErrorList),
30 Status503(models::seller_wallet_2024_03_01::ErrorList),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListAccountBalancesError {
38 Status400(models::seller_wallet_2024_03_01::ErrorList),
39 Status403(models::seller_wallet_2024_03_01::ErrorList),
40 Status404(models::seller_wallet_2024_03_01::ErrorList),
41 Status408(models::seller_wallet_2024_03_01::ErrorList),
42 Status413(models::seller_wallet_2024_03_01::ErrorList),
43 Status415(models::seller_wallet_2024_03_01::ErrorList),
44 Status429(models::seller_wallet_2024_03_01::ErrorList),
45 Status500(models::seller_wallet_2024_03_01::ErrorList),
46 Status503(models::seller_wallet_2024_03_01::ErrorList),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ListAccountsError {
54 Status400(models::seller_wallet_2024_03_01::ErrorList),
55 Status403(models::seller_wallet_2024_03_01::ErrorList),
56 Status404(models::seller_wallet_2024_03_01::ErrorList),
57 Status408(models::seller_wallet_2024_03_01::ErrorList),
58 Status413(models::seller_wallet_2024_03_01::ErrorList),
59 Status415(models::seller_wallet_2024_03_01::ErrorList),
60 Status429(models::seller_wallet_2024_03_01::ErrorList),
61 Status500(models::seller_wallet_2024_03_01::ErrorList),
62 Status503(models::seller_wallet_2024_03_01::ErrorList),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn get_account(configuration: &configuration::Configuration, account_id: &str) -> Result<models::seller_wallet_2024_03_01::BankAccount, Error<GetAccountError>> {
69 let p_account_id = account_id;
71
72 let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts/{accountId}", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
73 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
74
75 if let Some(ref user_agent) = configuration.user_agent {
76 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77 }
78
79 let req = req_builder.build()?;
80 let resp = configuration.client.execute(req).await?;
81
82 let status = resp.status();
83 let content_type = resp
84 .headers()
85 .get("content-type")
86 .and_then(|v| v.to_str().ok())
87 .unwrap_or("application/octet-stream");
88 let content_type = super::ContentType::from(content_type);
89
90 if !status.is_client_error() && !status.is_server_error() {
91 let content = resp.text().await?;
92 match content_type {
93 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BankAccount`"))),
95 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::seller_wallet_2024_03_01::BankAccount`")))),
96 }
97 } else {
98 let content = resp.text().await?;
99 let entity: Option<GetAccountError> = serde_json::from_str(&content).ok();
100 Err(Error::ResponseError(ResponseContent { status, content, entity }))
101 }
102}
103
104pub async fn list_account_balances(configuration: &configuration::Configuration, account_id: &str) -> Result<models::seller_wallet_2024_03_01::BalanceListing, Error<ListAccountBalancesError>> {
106 let p_account_id = account_id;
108
109 let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts/{accountId}/balance", configuration.base_path, accountId=crate::apis::urlencode(p_account_id));
110 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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
116 let req = req_builder.build()?;
117 let resp = configuration.client.execute(req).await?;
118
119 let status = resp.status();
120 let content_type = resp
121 .headers()
122 .get("content-type")
123 .and_then(|v| v.to_str().ok())
124 .unwrap_or("application/octet-stream");
125 let content_type = super::ContentType::from(content_type);
126
127 if !status.is_client_error() && !status.is_server_error() {
128 let content = resp.text().await?;
129 match content_type {
130 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
131 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BalanceListing`"))),
132 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::seller_wallet_2024_03_01::BalanceListing`")))),
133 }
134 } else {
135 let content = resp.text().await?;
136 let entity: Option<ListAccountBalancesError> = serde_json::from_str(&content).ok();
137 Err(Error::ResponseError(ResponseContent { status, content, entity }))
138 }
139}
140
141pub async fn list_accounts(configuration: &configuration::Configuration, marketplace_id: &str) -> Result<models::seller_wallet_2024_03_01::BankAccountListing, Error<ListAccountsError>> {
143 let p_marketplace_id = marketplace_id;
145
146 let uri_str = format!("{}/finances/transfers/wallet/2024-03-01/accounts", configuration.base_path);
147 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
148
149 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
150 if let Some(ref user_agent) = configuration.user_agent {
151 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
152 }
153
154 let req = req_builder.build()?;
155 let resp = configuration.client.execute(req).await?;
156
157 let status = resp.status();
158 let content_type = resp
159 .headers()
160 .get("content-type")
161 .and_then(|v| v.to_str().ok())
162 .unwrap_or("application/octet-stream");
163 let content_type = super::ContentType::from(content_type);
164
165 if !status.is_client_error() && !status.is_server_error() {
166 let content = resp.text().await?;
167 match content_type {
168 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
169 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::seller_wallet_2024_03_01::BankAccountListing`"))),
170 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::seller_wallet_2024_03_01::BankAccountListing`")))),
171 }
172 } else {
173 let content = resp.text().await?;
174 let entity: Option<ListAccountsError> = serde_json::from_str(&content).ok();
175 Err(Error::ResponseError(ResponseContent { status, content, entity }))
176 }
177}
178