add docs, add instance.get_user()

This commit is contained in:
bitfl0wer 2023-05-07 11:54:49 +02:00
parent 3cd19ed15e
commit 7904b3d9f8
1 changed files with 37 additions and 0 deletions

View File

@ -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<UserObject, InstanceServerError> {
User::get(
&token,
&self.urls.get_api().to_string(),
id,
&mut self.limits,
)
.await
}
}