From 50ecc78da0128e5ee080c7d1e48f238caa48f69b Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 7 May 2023 11:54:49 +0200 Subject: [PATCH] add docs, add instance.get_user() --- src/api/users/users.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/api/users/users.rs b/src/api/users/users.rs index 2692cbb..e4d1678 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -4,9 +4,20 @@ use crate::{ types::{User, UserObject}, }, errors::InstanceServerError, + instance::Instance, }; impl<'a> User<'a> { + /** + Get a user object by id, or get the current user. + # Arguments + * `token` - A valid access token for the API. + * `url_api` - The URL to the API. + * `id` - The id of the user that will be retrieved. If this is None, the current user will be retrieved. + * `instance_limits` - The [`Limits`] of the instance. + # Errors + * [`InstanceServerError`] - If the request fails. + */ pub async fn get( token: &String, url_api: &String, @@ -35,3 +46,29 @@ impl<'a> User<'a> { } } } + +impl<'a> Instance<'a> { + /** + Get a user object by id, or get the current user. + # Arguments + * `token` - A valid access token for the API. + * `id` - The id of the user that will be retrieved. If this is None, the current user will be retrieved. + # Errors + * [`InstanceServerError`] - If the request fails. + # Notes + This function is a wrapper around [`User::get`]. + */ + pub async fn get_user( + &mut self, + token: String, + id: Option<&String>, + ) -> Result { + User::get( + &token, + &self.urls.get_api().to_string(), + id, + &mut self.limits, + ) + .await + } +}