Refactor modify() to take less boilerplate args
This commit is contained in:
parent
ebeaf31343
commit
072d99e879
|
@ -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.
|
/// 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(
|
pub async fn modify(
|
||||||
modify_data: ChannelModifySchema,
|
modify_data: ChannelModifySchema,
|
||||||
token: &str,
|
|
||||||
url_api: &str,
|
|
||||||
channel_id: &str,
|
channel_id: &str,
|
||||||
limits_user: &mut Limits,
|
user: &mut UserMeta,
|
||||||
limits_instance: &mut Limits,
|
|
||||||
) -> Result<Channel, InstanceServerError> {
|
) -> Result<Channel, InstanceServerError> {
|
||||||
|
let mut belongs_to = user.belongs_to.borrow_mut();
|
||||||
let request = Client::new()
|
let request = Client::new()
|
||||||
.patch(format!("{}/channels/{}/", url_api, channel_id))
|
.patch(format!(
|
||||||
.bearer_auth(token)
|
"{}/channels/{}/",
|
||||||
|
belongs_to.urls.get_api(),
|
||||||
|
channel_id
|
||||||
|
))
|
||||||
|
.bearer_auth(user.token())
|
||||||
.body(to_string(&modify_data).unwrap());
|
.body(to_string(&modify_data).unwrap());
|
||||||
let channel = match LimitedRequester::new()
|
let channel = match LimitedRequester::new()
|
||||||
.await
|
.await
|
||||||
.send_request(
|
.send_request(
|
||||||
request,
|
request,
|
||||||
crate::api::limits::LimitType::Channel,
|
crate::api::limits::LimitType::Channel,
|
||||||
limits_instance,
|
&mut belongs_to.limits,
|
||||||
limits_user,
|
&mut user.limits,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,11 +48,8 @@ async fn modify_channel() {
|
||||||
};
|
};
|
||||||
let result = Channel::modify(
|
let result = Channel::modify(
|
||||||
modify_data,
|
modify_data,
|
||||||
&bundle.user.token,
|
|
||||||
bundle.instance.urls.get_api(),
|
|
||||||
&bundle.channel.id.to_string(),
|
&bundle.channel.id.to_string(),
|
||||||
&mut bundle.user.limits,
|
&mut bundle.user,
|
||||||
&mut bundle.instance.limits,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue