From 072d99e8795f1f4dd9127e9dea7a1721a9d86bdd Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:11:12 +0200 Subject: [PATCH] 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();