btcpay_client/apis/
users_api.rs

1/*
2 * BTCPay Greenfield API
3 *
4 * A full API to use your BTCPay Server
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`users_create_user`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum UsersCreateUserError {
22    Status400(Vec<crate::models::ValidationProblemDetailsInner>),
23    Status401(),
24    Status403(),
25    Status429(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`users_delete_current_user`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum UsersDeleteCurrentUserError {
33    Status404(),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`users_delete_user`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UsersDeleteUserError {
41    Status401(),
42    Status403(),
43    Status404(),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`users_get_current_user`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum UsersGetCurrentUserError {
51    Status404(),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`users_get_user`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum UsersGetUserError {
59    Status401(),
60    Status403(),
61    Status404(),
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method [`users_get_users`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum UsersGetUsersError {
69    Status401(),
70    Status403(),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`users_toggle_user_lock`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum UsersToggleUserLockError {
78    Status401(),
79    Status403(),
80    Status404(),
81    UnknownValue(serde_json::Value),
82}
83
84
85/// Create a new user.  This operation can be called without authentication in any of this cases: * There is not any administrator yet on the server, * The subscriptions are not disabled in the server's policies.  If the first administrator is created by this call, subscriptions are automatically disabled.
86pub async fn users_create_user(configuration: &configuration::Configuration, users_create_user_request: crate::models::UsersCreateUserRequest) -> Result<crate::models::ApplicationUserData, Error<UsersCreateUserError>> {
87    let local_var_configuration = configuration;
88
89    let local_var_client = &local_var_configuration.client;
90
91    let local_var_uri_str = format!("{}/api/v1/users", local_var_configuration.base_path);
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
96    }
97    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
98        let local_var_key = local_var_apikey.key.clone();
99        let local_var_value = match local_var_apikey.prefix {
100            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
101            None => local_var_key,
102        };
103        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
104    };
105    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
106        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
107    };
108    local_var_req_builder = local_var_req_builder.json(&users_create_user_request);
109
110    let local_var_req = local_var_req_builder.build()?;
111    let local_var_resp = local_var_client.execute(local_var_req).await?;
112
113    let local_var_status = local_var_resp.status();
114    let local_var_content = local_var_resp.text().await?;
115
116    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117        serde_json::from_str(&local_var_content).map_err(Error::from)
118    } else {
119        let local_var_entity: Option<UsersCreateUserError> = serde_json::from_str(&local_var_content).ok();
120        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
121        Err(Error::ResponseError(local_var_error))
122    }
123}
124
125/// Deletes user profile and associated user data for user making the request
126pub async fn users_delete_current_user(configuration: &configuration::Configuration, ) -> Result<(), Error<UsersDeleteCurrentUserError>> {
127    let local_var_configuration = configuration;
128
129    let local_var_client = &local_var_configuration.client;
130
131    let local_var_uri_str = format!("{}/api/v1/users/me", local_var_configuration.base_path);
132    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
133
134    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
136    }
137    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
138        let local_var_key = local_var_apikey.key.clone();
139        let local_var_value = match local_var_apikey.prefix {
140            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
141            None => local_var_key,
142        };
143        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
144    };
145    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
146        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
147    };
148
149    let local_var_req = local_var_req_builder.build()?;
150    let local_var_resp = local_var_client.execute(local_var_req).await?;
151
152    let local_var_status = local_var_resp.status();
153    let local_var_content = local_var_resp.text().await?;
154
155    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
156        Ok(())
157    } else {
158        let local_var_entity: Option<UsersDeleteCurrentUserError> = serde_json::from_str(&local_var_content).ok();
159        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
160        Err(Error::ResponseError(local_var_error))
161    }
162}
163
164/// Delete a user.  Must be an admin to perform this operation.  Attempting to delete the only admin user will not succeed.  All data associated with the user will be deleted as well if the operation succeeds.
165pub async fn users_delete_user(configuration: &configuration::Configuration, id_or_email: &str) -> Result<(), Error<UsersDeleteUserError>> {
166    let local_var_configuration = configuration;
167
168    let local_var_client = &local_var_configuration.client;
169
170    let local_var_uri_str = format!("{}/api/v1/users/{idOrEmail}", local_var_configuration.base_path, idOrEmail=crate::apis::urlencode(id_or_email));
171    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
172
173    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
174        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
175    }
176    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
177        let local_var_key = local_var_apikey.key.clone();
178        let local_var_value = match local_var_apikey.prefix {
179            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
180            None => local_var_key,
181        };
182        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
183    };
184    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
185        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
186    };
187
188    let local_var_req = local_var_req_builder.build()?;
189    let local_var_resp = local_var_client.execute(local_var_req).await?;
190
191    let local_var_status = local_var_resp.status();
192    let local_var_content = local_var_resp.text().await?;
193
194    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
195        Ok(())
196    } else {
197        let local_var_entity: Option<UsersDeleteUserError> = serde_json::from_str(&local_var_content).ok();
198        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
199        Err(Error::ResponseError(local_var_error))
200    }
201}
202
203/// View information about the current user
204pub async fn users_get_current_user(configuration: &configuration::Configuration, ) -> Result<crate::models::ApplicationUserData, Error<UsersGetCurrentUserError>> {
205    let local_var_configuration = configuration;
206
207    let local_var_client = &local_var_configuration.client;
208
209    let local_var_uri_str = format!("{}/api/v1/users/me", local_var_configuration.base_path);
210    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
211
212    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
213        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
214    }
215    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
216        let local_var_key = local_var_apikey.key.clone();
217        let local_var_value = match local_var_apikey.prefix {
218            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
219            None => local_var_key,
220        };
221        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
222    };
223    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
224        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
225    };
226
227    let local_var_req = local_var_req_builder.build()?;
228    let local_var_resp = local_var_client.execute(local_var_req).await?;
229
230    let local_var_status = local_var_resp.status();
231    let local_var_content = local_var_resp.text().await?;
232
233    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
234        serde_json::from_str(&local_var_content).map_err(Error::from)
235    } else {
236        let local_var_entity: Option<UsersGetCurrentUserError> = serde_json::from_str(&local_var_content).ok();
237        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
238        Err(Error::ResponseError(local_var_error))
239    }
240}
241
242/// Get 1 user by ID or Email.
243pub async fn users_get_user(configuration: &configuration::Configuration, id_or_email: &str) -> Result<(), Error<UsersGetUserError>> {
244    let local_var_configuration = configuration;
245
246    let local_var_client = &local_var_configuration.client;
247
248    let local_var_uri_str = format!("{}/api/v1/users/{idOrEmail}", local_var_configuration.base_path, idOrEmail=crate::apis::urlencode(id_or_email));
249    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
250
251    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
252        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
253    }
254    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
255        let local_var_key = local_var_apikey.key.clone();
256        let local_var_value = match local_var_apikey.prefix {
257            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
258            None => local_var_key,
259        };
260        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
261    };
262    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
263        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
264    };
265
266    let local_var_req = local_var_req_builder.build()?;
267    let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269    let local_var_status = local_var_resp.status();
270    let local_var_content = local_var_resp.text().await?;
271
272    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
273        Ok(())
274    } else {
275        let local_var_entity: Option<UsersGetUserError> = serde_json::from_str(&local_var_content).ok();
276        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
277        Err(Error::ResponseError(local_var_error))
278    }
279}
280
281/// Load all users that exist.
282pub async fn users_get_users(configuration: &configuration::Configuration, ) -> Result<(), Error<UsersGetUsersError>> {
283    let local_var_configuration = configuration;
284
285    let local_var_client = &local_var_configuration.client;
286
287    let local_var_uri_str = format!("{}/api/v1/users", local_var_configuration.base_path);
288    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
289
290    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
291        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292    }
293    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
294        let local_var_key = local_var_apikey.key.clone();
295        let local_var_value = match local_var_apikey.prefix {
296            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
297            None => local_var_key,
298        };
299        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
300    };
301    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
302        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
303    };
304
305    let local_var_req = local_var_req_builder.build()?;
306    let local_var_resp = local_var_client.execute(local_var_req).await?;
307
308    let local_var_status = local_var_resp.status();
309    let local_var_content = local_var_resp.text().await?;
310
311    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
312        Ok(())
313    } else {
314        let local_var_entity: Option<UsersGetUsersError> = serde_json::from_str(&local_var_content).ok();
315        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
316        Err(Error::ResponseError(local_var_error))
317    }
318}
319
320/// Lock or unlock a user.  Must be an admin to perform this operation.  Attempting to lock the only admin user will not succeed.
321pub async fn users_toggle_user_lock(configuration: &configuration::Configuration, id_or_email: &str, lock_user_request: Option<crate::models::LockUserRequest>) -> Result<(), Error<UsersToggleUserLockError>> {
322    let local_var_configuration = configuration;
323
324    let local_var_client = &local_var_configuration.client;
325
326    let local_var_uri_str = format!("{}/api/v1/users/{idOrEmail}/lock", local_var_configuration.base_path, idOrEmail=crate::apis::urlencode(id_or_email));
327    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
328
329    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
330        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
331    }
332    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
333        let local_var_key = local_var_apikey.key.clone();
334        let local_var_value = match local_var_apikey.prefix {
335            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
336            None => local_var_key,
337        };
338        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
339    };
340    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
341        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
342    };
343    local_var_req_builder = local_var_req_builder.json(&lock_user_request);
344
345    let local_var_req = local_var_req_builder.build()?;
346    let local_var_resp = local_var_client.execute(local_var_req).await?;
347
348    let local_var_status = local_var_resp.status();
349    let local_var_content = local_var_resp.text().await?;
350
351    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
352        Ok(())
353    } else {
354        let local_var_entity: Option<UsersToggleUserLockError> = serde_json::from_str(&local_var_content).ok();
355        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
356        Err(Error::ResponseError(local_var_error))
357    }
358}
359