From 3e4840d7a6b24b8f803a0d65e052783a2429fde3 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:01:17 +0200 Subject: [PATCH 01/11] Refactor get() to take less boilerplate args --- src/api/channels/channels.rs | 21 ++++++++++++--------- tests/channel.rs | 14 ++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index bfe9959..21026b6 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -4,28 +4,31 @@ use serde_json::{from_str, to_string}; use crate::{ api::limits::Limits, errors::InstanceServerError, + instance::UserMeta, limit::LimitedRequester, types::{Channel, ChannelModifySchema}, }; impl Channel { pub async fn get( - token: &str, - url_api: &str, + user: &mut UserMeta, channel_id: &str, - limits_user: &mut Limits, - limits_instance: &mut Limits, ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); let request = Client::new() - .get(format!("{}/channels/{}/", url_api, channel_id)) - .bearer_auth(token); + .get(format!( + "{}/channels/{}/", + belongs_to.urls.get_api(), + channel_id + )) + .bearer_auth(user.token()); let mut requester = LimitedRequester::new().await; let result = match requester .send_request( request, crate::api::limits::LimitType::Guild, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await { @@ -36,7 +39,7 @@ impl Channel { match from_str::(&result_text) { Ok(object) => Ok(object), Err(e) => Err(InstanceServerError::RequestErrorError { - url: format!("{}/channels/{}/", url_api, channel_id), + url: format!("{}/channels/{}/", belongs_to.urls.get_api(), channel_id), error: e.to_string(), }), } diff --git a/tests/channel.rs b/tests/channel.rs index 56f1ce5..58776b0 100644 --- a/tests/channel.rs +++ b/tests/channel.rs @@ -5,19 +5,13 @@ use chorus::types::{self, Channel}; async fn get_channel() { let mut bundle = common::setup().await; let bundle_channel = bundle.channel.clone(); - let bundle_user = &mut bundle.user; + let mut bundle_user = &mut bundle.user; assert_eq!( bundle_channel, - Channel::get( - bundle_user.token.as_str(), - bundle.instance.urls.get_api(), - &bundle_channel.id.to_string(), - &mut bundle_user.limits, - &mut bundle.instance.limits - ) - .await - .unwrap() + Channel::get(&mut bundle_user, &bundle_channel.id.to_string(),) + .await + .unwrap() ); common::teardown(bundle).await } From ebeaf313435ed60462ae06e5b261eb689d84feac Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:08:52 +0200 Subject: [PATCH 02/11] Refactor delete() to take less boilerplate args --- src/api/channels/channels.rs | 21 ++++++++++----------- tests/channel.rs | 11 +---------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 21026b6..4193933 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -58,23 +58,22 @@ impl Channel { /// # Returns /// /// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful. - pub async fn delete( - self, - token: &str, - url_api: &str, - limits_user: &mut Limits, - limits_instance: &mut Limits, - ) -> Option { + pub async fn delete(self, user: &mut UserMeta) -> Option { + let mut belongs_to = user.belongs_to.borrow_mut(); let request = Client::new() - .delete(format!("{}/channels/{}/", url_api, self.id.to_string())) - .bearer_auth(token); + .delete(format!( + "{}/channels/{}/", + belongs_to.urls.get_api(), + self.id.to_string() + )) + .bearer_auth(user.token()); match LimitedRequester::new() .await .send_request( request, crate::api::limits::LimitType::Channel, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await { diff --git a/tests/channel.rs b/tests/channel.rs index 58776b0..101fe8a 100644 --- a/tests/channel.rs +++ b/tests/channel.rs @@ -19,16 +19,7 @@ async fn get_channel() { #[tokio::test] async fn delete_channel() { let mut bundle = common::setup().await; - let result = bundle - .channel - .clone() - .delete( - &bundle.user.token, - bundle.instance.urls.get_api(), - &mut bundle.user.limits, - &mut bundle.instance.limits, - ) - .await; + let result = bundle.channel.clone().delete(&mut bundle.user).await; assert!(result.is_none()); common::teardown(bundle).await } From 072d99e8795f1f4dd9127e9dea7a1721a9d86bdd Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:11:12 +0200 Subject: [PATCH 03/11] Refactor modify() to take less boilerplate args --- src/api/channels/channels.rs | 18 ++++++++++-------- tests/channel.rs | 5 +---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 4193933..690ec28 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -98,23 +98,25 @@ impl Channel { /// A `Result` that contains a `Channel` object if the request was successful, or an `InstanceServerError` if an error occurred during the request. pub async fn modify( modify_data: ChannelModifySchema, - token: &str, - url_api: &str, channel_id: &str, - limits_user: &mut Limits, - limits_instance: &mut Limits, + user: &mut UserMeta, ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); let request = Client::new() - .patch(format!("{}/channels/{}/", url_api, channel_id)) - .bearer_auth(token) + .patch(format!( + "{}/channels/{}/", + belongs_to.urls.get_api(), + channel_id + )) + .bearer_auth(user.token()) .body(to_string(&modify_data).unwrap()); let channel = match LimitedRequester::new() .await .send_request( request, crate::api::limits::LimitType::Channel, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await { diff --git a/tests/channel.rs b/tests/channel.rs index 101fe8a..85b019b 100644 --- a/tests/channel.rs +++ b/tests/channel.rs @@ -48,11 +48,8 @@ async fn modify_channel() { }; let result = Channel::modify( modify_data, - &bundle.user.token, - bundle.instance.urls.get_api(), &bundle.channel.id.to_string(), - &mut bundle.user.limits, - &mut bundle.instance.limits, + &mut bundle.user, ) .await .unwrap(); From c43e861586f6006ee61030044d7a0e31d1d3945a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:15:05 +0200 Subject: [PATCH 04/11] Refactor message::send() --- src/api/channels/messages.rs | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/api/channels/messages.rs b/src/api/channels/messages.rs index 7b43eef..336d563 100644 --- a/src/api/channels/messages.rs +++ b/src/api/channels/messages.rs @@ -4,7 +4,6 @@ pub mod messages { use reqwest::{multipart, Client}; use serde_json::to_string; - use crate::api::limits::Limits; use crate::instance::UserMeta; use crate::limit::LimitedRequester; use crate::types::{Message, MessageSendSchema, PartialDiscordFileAttachment}; @@ -22,27 +21,26 @@ pub mod messages { * [`InstanceServerError`] - If the message cannot be sent. */ pub async fn send<'a>( - url_api: String, + user: &mut UserMeta, channel_id: String, message: &mut MessageSendSchema, files: Option>, - token: String, - limits_user: &mut Limits, - limits_instance: &mut Limits, ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); + let url_api = belongs_to.urls.get_api(); let mut requester = LimitedRequester::new().await; if files.is_none() { let message_request = Client::new() .post(format!("{}/channels/{}/messages/", url_api, channel_id)) - .bearer_auth(token) + .bearer_auth(user.token()) .body(to_string(message).unwrap()); requester .send_request( message_request, crate::api::limits::LimitType::Channel, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await } else { @@ -75,15 +73,15 @@ pub mod messages { let message_request = Client::new() .post(format!("{}/channels/{}/messages/", url_api, channel_id)) - .bearer_auth(token) + .bearer_auth(user.token()) .multipart(form); requester .send_request( message_request, crate::api::limits::LimitType::Channel, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await } @@ -91,24 +89,25 @@ pub mod messages { } impl UserMeta { + /// Shorthand call for Message::send() + /** + Sends a message to the Spacebar server. + # Arguments + * `url_api` - The URL of the Spacebar server's API. + * `message` - The [`Message`] that will be sent to the Spacebar server. + * `limits_user` - The [`Limits`] of the user. + * `limits_instance` - The [`Limits`] of the instance. + * `requester` - The [`LimitedRequester`] that will be used to make requests to the Spacebar server. + # Errors + * [`InstanceServerError`] - If the message cannot be sent. + */ pub async fn send_message( &mut self, message: &mut MessageSendSchema, channel_id: String, files: Option>, ) -> Result { - let token = self.token().clone(); - let mut belongs_to = self.belongs_to.borrow_mut(); - Message::send( - belongs_to.urls.get_api().to_string(), - channel_id, - message, - files, - token, - &mut self.limits, - &mut belongs_to.limits, - ) - .await + Message::send(self, channel_id, message, files).await } } } From 69993820f94ee667c16b8e135a506b700637645c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:16:43 +0200 Subject: [PATCH 05/11] Refactor Guild create --- src/api/guilds/guilds.rs | 6 +++--- tests/guild.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 45482b3..e153f09 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -27,10 +27,10 @@ impl Guild { /// pub async fn create( user: &mut UserMeta, - url_api: &str, guild_create_schema: GuildCreateSchema, ) -> Result { - let url = format!("{}/guilds/", url_api); + let belongs_to = user.belongs_to.borrow_mut(); + let url = format!("{}/guilds/", belongs_to.urls.get_api()); let mut limits_user = user.limits.get_as_mut(); let mut limits_instance = &mut user.belongs_to.borrow_mut().limits; let request = reqwest::Client::new() @@ -52,7 +52,7 @@ impl Guild { }; let id: GuildCreateResponse = from_str(&result.text().await.unwrap()).unwrap(); let guild = Guild::get( - url_api, + belongs_to.urls.get_api(), &id.id, &user.token, &mut limits_user, diff --git a/tests/guild.rs b/tests/guild.rs index 48794d8..56cb51d 100644 --- a/tests/guild.rs +++ b/tests/guild.rs @@ -15,7 +15,7 @@ async fn guild_creation_deletion() { rules_channel_id: None, }; - let guild = Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema) + let guild = Guild::create(&mut bundle.user, guild_create_schema) .await .unwrap(); From f986b33878daf818c4db00b940f2b03d511e4272 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:46:17 +0200 Subject: [PATCH 06/11] Remove unnecessary lifetime --- src/api/channels/messages.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/channels/messages.rs b/src/api/channels/messages.rs index 336d563..cd2b899 100644 --- a/src/api/channels/messages.rs +++ b/src/api/channels/messages.rs @@ -20,7 +20,7 @@ pub mod messages { # Errors * [`InstanceServerError`] - If the message cannot be sent. */ - pub async fn send<'a>( + pub async fn send( user: &mut UserMeta, channel_id: String, message: &mut MessageSendSchema, From b501aca5b2483de4a708db141315b51a50464cc9 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:46:43 +0200 Subject: [PATCH 07/11] Refactor create() and get() --- src/api/guilds/guilds.rs | 32 ++++++++++++++++++++++---------- tests/common/mod.rs | 4 +--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index e153f09..02bf58d 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -29,10 +29,8 @@ impl Guild { user: &mut UserMeta, guild_create_schema: GuildCreateSchema, ) -> Result { - let belongs_to = user.belongs_to.borrow_mut(); + let mut belongs_to = user.belongs_to.borrow_mut(); let url = format!("{}/guilds/", belongs_to.urls.get_api()); - let mut limits_user = user.limits.get_as_mut(); - let mut limits_instance = &mut user.belongs_to.borrow_mut().limits; let request = reqwest::Client::new() .post(url.clone()) .bearer_auth(user.token.clone()) @@ -42,8 +40,8 @@ impl Guild { .send_request( request, crate::api::limits::LimitType::Guild, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await { @@ -51,12 +49,12 @@ impl Guild { Err(e) => return Err(e), }; let id: GuildCreateResponse = from_str(&result.text().await.unwrap()).unwrap(); - let guild = Guild::get( - belongs_to.urls.get_api(), + let guild = Guild::_get( + belongs_to.clone().urls.get_api(), &id.id, &user.token, - &mut limits_user, - &mut limits_instance, + &mut user.limits, + &mut belongs_to.limits, ) .await .unwrap(); @@ -210,7 +208,21 @@ impl Guild { /// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits. /// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits. /// - pub async fn get( + pub async fn get(user: &mut UserMeta, guild_id: &str) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); + Guild::_get( + &format!("{}", belongs_to.urls.get_api()), + guild_id, + &user.token, + &mut user.limits, + &mut belongs_to.limits, + ) + .await + } + + /// For internal use. Does the same as the public get method, but does not require a second, mutable + /// borrow of `UserMeta::belongs_to`, when used in conjunction with other methods, which borrow `UserMeta::belongs_to`. + async fn _get( url_api: &str, guild_id: &str, token: &str, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 61fb2fc..2bb0883 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -65,9 +65,7 @@ pub async fn setup() -> TestBundle { video_quality_mode: None, }; let mut user = instance.register_account(®).await.unwrap(); - let guild = Guild::create(&mut user, urls.get_api(), guild_create_schema) - .await - .unwrap(); + let guild = Guild::create(&mut user, guild_create_schema).await.unwrap(); let channel = Channel::create( &user.token, urls.get_api(), From 03e5a83d84448ccd7ead166f5fbee81208d2713c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:51:12 +0200 Subject: [PATCH 08/11] Refactor delete() --- src/api/guilds/guilds.rs | 15 +++++---------- tests/common/mod.rs | 7 +------ tests/guild.rs | 8 +------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 02bf58d..aef5eb4 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -85,14 +85,9 @@ impl Guild { /// None => println!("Guild deleted successfully"), /// } /// ``` - pub async fn delete( - user: &mut UserMeta, - url_api: &str, - guild_id: &str, - ) -> Option { - let url = format!("{}/guilds/{}/delete/", url_api, guild_id); - let limits_user = user.limits.get_as_mut(); - let limits_instance = &mut user.belongs_to.borrow_mut().limits; + pub async fn delete(user: &mut UserMeta, guild_id: &str) -> Option { + let mut belongs_to = user.belongs_to.borrow_mut(); + let url = format!("{}/guilds/{}/delete/", belongs_to.urls.get_api(), guild_id); let request = reqwest::Client::new() .post(url.clone()) .bearer_auth(user.token.clone()); @@ -101,8 +96,8 @@ impl Guild { .send_request( request, crate::api::limits::LimitType::Guild, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await; if result.is_err() { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2bb0883..f8991e3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -88,11 +88,6 @@ pub async fn setup() -> TestBundle { // Teardown method to clean up after a test. pub async fn teardown(mut bundle: TestBundle) { - Guild::delete( - &mut bundle.user, - bundle.instance.urls.get_api(), - &bundle.guild.id.to_string(), - ) - .await; + Guild::delete(&mut bundle.user, &bundle.guild.id.to_string()).await; bundle.user.delete().await; } diff --git a/tests/guild.rs b/tests/guild.rs index 56cb51d..8bd0838 100644 --- a/tests/guild.rs +++ b/tests/guild.rs @@ -19,13 +19,7 @@ async fn guild_creation_deletion() { .await .unwrap(); - match Guild::delete( - &mut bundle.user, - bundle.urls.get_api(), - &guild.id.to_string(), - ) - .await - { + match Guild::delete(&mut bundle.user, &guild.id.to_string()).await { None => assert!(true), Some(_) => assert!(false), } From 671c5d6191c12e7e29fa58897317cb72bf7304f6 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:57:23 +0200 Subject: [PATCH 09/11] Refactor create --- src/api/guilds/guilds.rs | 33 ++++++++++++++++++++++++--------- tests/common/mod.rs | 13 +++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index aef5eb4..118a25e 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -122,19 +122,17 @@ impl Guild { /// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error. pub async fn create_channel( &self, - url_api: &str, - token: &str, + user: &mut UserMeta, schema: ChannelCreateSchema, - limits_user: &mut Limits, - limits_instance: &mut Limits, ) -> Result { - Channel::create( - token, - url_api, + let mut belongs_to = user.belongs_to.borrow_mut(); + Channel::_create( + &user.token, + &format!("{}", belongs_to.urls.get_api()), &self.id.to_string(), schema, - limits_user, - limits_instance, + &mut user.limits, + &mut belongs_to.limits, ) .await } @@ -261,6 +259,23 @@ impl Channel { /// /// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error. pub async fn create( + user: &mut UserMeta, + guild_id: &str, + schema: ChannelCreateSchema, + ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); + Channel::_create( + &user.token, + &format!("{}", belongs_to.urls.get_api()), + guild_id, + schema, + &mut user.limits, + &mut belongs_to.limits, + ) + .await + } + + async fn _create( token: &str, url_api: &str, guild_id: &str, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f8991e3..4b20399 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -66,16 +66,9 @@ pub async fn setup() -> TestBundle { }; let mut user = instance.register_account(®).await.unwrap(); let guild = Guild::create(&mut user, guild_create_schema).await.unwrap(); - let channel = Channel::create( - &user.token, - urls.get_api(), - &guild.id.to_string(), - channel_create_schema, - &mut user.limits, - &mut instance.limits, - ) - .await - .unwrap(); + let channel = Channel::create(&mut user, &guild.id.to_string(), channel_create_schema) + .await + .unwrap(); TestBundle { urls, From 315c5a00cf3f20845e53c89b2b82817c8f2e2c8d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:59:13 +0200 Subject: [PATCH 10/11] Refactor channels() --- src/api/guilds/guilds.rs | 17 ++++++----------- tests/guild.rs | 11 +---------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 118a25e..f267e55 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -146,27 +146,22 @@ impl Guild { /// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits. /// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits. /// - pub async fn channels( - &self, - url_api: &str, - token: &str, - limits_user: &mut Limits, - limits_instance: &mut Limits, - ) -> Result, InstanceServerError> { + pub async fn channels(&self, user: &mut UserMeta) -> Result, InstanceServerError> { + let mut belongs_to = user.belongs_to.borrow_mut(); let request = Client::new() .get(format!( "{}/guilds/{}/channels/", - url_api, + belongs_to.urls.get_api(), self.id.to_string() )) - .bearer_auth(token); + .bearer_auth(user.token()); let result = match LimitedRequester::new() .await .send_request( request, crate::api::limits::LimitType::Guild, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await { diff --git a/tests/guild.rs b/tests/guild.rs index 8bd0838..8143532 100644 --- a/tests/guild.rs +++ b/tests/guild.rs @@ -31,16 +31,7 @@ async fn get_channels() { let mut bundle = common::setup().await; println!( "{:?}", - bundle - .guild - .channels( - bundle.instance.urls.get_api(), - &bundle.user.token, - &mut bundle.user.limits, - &mut bundle.instance.limits, - ) - .await - .unwrap() + bundle.guild.channels(&mut bundle.user).await.unwrap() ); common::teardown(bundle).await; } From 9943fcc55f47635330e69c181c866a893046e503 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 30 May 2023 23:04:22 +0200 Subject: [PATCH 11/11] Refactored users() as much as possible --- src/api/users/users.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/api/users/users.rs b/src/api/users/users.rs index dacff1f..2cdaa74 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -21,12 +21,10 @@ impl UserMeta { * [`InstanceServerError`] - If the request fails. */ pub async fn get( - token: &String, - url_api: &String, + user: &mut UserMeta, id: Option<&String>, - instance_limits: &mut Limits, ) -> Result { - User::get(token, url_api, id, instance_limits).await + User::get(user, id).await } pub async fn get_settings( @@ -116,10 +114,24 @@ impl UserMeta { impl User { pub async fn get( - token: &String, - url_api: &String, + user: &mut UserMeta, + id: Option<&String>, + ) -> Result { + let mut belongs_to = user.belongs_to.borrow_mut(); + User::_get( + &user.token(), + &format!("{}", belongs_to.urls.get_api()), + &mut belongs_to.limits, + id, + ) + .await + } + + async fn _get( + token: &str, + url_api: &str, + limits_instance: &mut Limits, id: Option<&String>, - instance_limits: &mut Limits, ) -> Result { let url: String; if id.is_none() { @@ -129,12 +141,12 @@ impl User { } let request = reqwest::Client::new().get(url).bearer_auth(token); let mut requester = crate::limit::LimitedRequester::new().await; - let mut cloned_limits = instance_limits.clone(); + let mut cloned_limits = limits_instance.clone(); match requester .send_request( request, crate::api::limits::LimitType::Ip, - instance_limits, + limits_instance, &mut cloned_limits, ) .await @@ -188,11 +200,11 @@ impl Instance { token: String, id: Option<&String>, ) -> Result { - UserMeta::get( + User::_get( &token, &self.urls.get_api().to_string(), - id, &mut self.limits, + id, ) .await }