From 5e5be4a9b4c5934fce2c4eea99927dbe075c5d60 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 21 May 2023 15:05:02 +0200 Subject: [PATCH] Add delete() to User --- src/api/users/users.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/api/users/users.rs b/src/api/users/users.rs index bc80bca..cf052aa 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -125,6 +125,35 @@ impl User { ); Ok(user_updated) } + + /// Sends a request to the server which deletes the user from the Instance. + /// + /// # Arguments + /// + /// * `self` - The `User` object to delete. + /// + /// # Returns + /// + /// Returns `None` if the user was successfully deleted, or an `InstanceServerError` if an error occurred. + pub async fn delete(mut self) -> Option { + let mut belongs_to = self.belongs_to.borrow_mut(); + let request = Client::new() + .post(format!("{}/users/@me/delete/", belongs_to.urls.get_api())) + .bearer_auth(self.token); + match LimitedRequester::new() + .await + .send_request( + request, + crate::api::limits::LimitType::Global, + &mut belongs_to.limits, + &mut self.limits, + ) + .await + { + Ok(_) => None, + Err(e) => Some(e), + } + } } impl Instance {