btcpay_client/apis/
stores_users_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum StoresAddStoreUserError {
22 Status400(Vec<crate::models::ValidationProblemDetailsInner>),
23 Status403(),
24 Status409(crate::models::ProblemDetails),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum StoresGetStoreUsersError {
32 Status403(),
33 Status404(),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum StoresRemoveStoreUserError {
41 Status400(Vec<crate::models::ValidationProblemDetailsInner>),
42 Status409(crate::models::ProblemDetails),
43 Status403(),
44 Status404(),
45 UnknownValue(serde_json::Value),
46}
47
48
49pub async fn stores_add_store_user(configuration: &configuration::Configuration, store_id: &str, store_user_data: crate::models::StoreUserData) -> Result<(), Error<StoresAddStoreUserError>> {
51 let local_var_configuration = configuration;
52
53 let local_var_client = &local_var_configuration.client;
54
55 let local_var_uri_str = format!("{}/api/v1/stores/{storeId}/users", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id));
56 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
57
58 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
59 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60 }
61 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
62 let local_var_key = local_var_apikey.key.clone();
63 let local_var_value = match local_var_apikey.prefix {
64 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
65 None => local_var_key,
66 };
67 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
68 };
69 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
70 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
71 };
72 local_var_req_builder = local_var_req_builder.json(&store_user_data);
73
74 let local_var_req = local_var_req_builder.build()?;
75 let local_var_resp = local_var_client.execute(local_var_req).await?;
76
77 let local_var_status = local_var_resp.status();
78 let local_var_content = local_var_resp.text().await?;
79
80 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81 Ok(())
82 } else {
83 let local_var_entity: Option<StoresAddStoreUserError> = serde_json::from_str(&local_var_content).ok();
84 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85 Err(Error::ResponseError(local_var_error))
86 }
87}
88
89pub async fn stores_get_store_users(configuration: &configuration::Configuration, store_id: &str) -> Result<Vec<crate::models::StoreData>, Error<StoresGetStoreUsersError>> {
91 let local_var_configuration = configuration;
92
93 let local_var_client = &local_var_configuration.client;
94
95 let local_var_uri_str = format!("{}/api/v1/stores/{storeId}/users", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id));
96 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
97
98 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100 }
101 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
102 let local_var_key = local_var_apikey.key.clone();
103 let local_var_value = match local_var_apikey.prefix {
104 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
105 None => local_var_key,
106 };
107 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
108 };
109 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
110 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
111 };
112
113 let local_var_req = local_var_req_builder.build()?;
114 let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116 let local_var_status = local_var_resp.status();
117 let local_var_content = local_var_resp.text().await?;
118
119 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120 serde_json::from_str(&local_var_content).map_err(Error::from)
121 } else {
122 let local_var_entity: Option<StoresGetStoreUsersError> = serde_json::from_str(&local_var_content).ok();
123 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
124 Err(Error::ResponseError(local_var_error))
125 }
126}
127
128pub async fn stores_remove_store_user(configuration: &configuration::Configuration, store_id: &str, user_id: &str) -> Result<(), Error<StoresRemoveStoreUserError>> {
130 let local_var_configuration = configuration;
131
132 let local_var_client = &local_var_configuration.client;
133
134 let local_var_uri_str = format!("{}/api/v1/stores/{storeId}/users/{userId}", local_var_configuration.base_path, storeId=crate::apis::urlencode(store_id), userId=crate::apis::urlencode(user_id));
135 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
136
137 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
138 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
139 }
140 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
141 let local_var_key = local_var_apikey.key.clone();
142 let local_var_value = match local_var_apikey.prefix {
143 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
144 None => local_var_key,
145 };
146 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
147 };
148 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
149 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
150 };
151
152 let local_var_req = local_var_req_builder.build()?;
153 let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155 let local_var_status = local_var_resp.status();
156 let local_var_content = local_var_resp.text().await?;
157
158 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159 Ok(())
160 } else {
161 let local_var_entity: Option<StoresRemoveStoreUserError> = serde_json::from_str(&local_var_content).ok();
162 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163 Err(Error::ResponseError(local_var_error))
164 }
165}
166