Move Channels::get() to channels.rs
This commit is contained in:
parent
377e619f77
commit
d762a25953
|
@ -0,0 +1,43 @@
|
|||
use reqwest::Client;
|
||||
use serde_json::from_str;
|
||||
|
||||
use crate::{
|
||||
api::{limits::Limits, types},
|
||||
errors::InstanceServerError,
|
||||
limit::LimitedRequester,
|
||||
};
|
||||
|
||||
impl types::Channel {
|
||||
pub async fn get(
|
||||
token: &str,
|
||||
url_api: &str,
|
||||
channel_id: &str,
|
||||
limits_user: &mut Limits,
|
||||
limits_instance: &mut Limits,
|
||||
) -> Result<types::Channel, InstanceServerError> {
|
||||
let request = Client::new()
|
||||
.get(format!("{}/channels/{}/", url_api, channel_id))
|
||||
.bearer_auth(token);
|
||||
let mut requester = LimitedRequester::new().await;
|
||||
let result = match requester
|
||||
.send_request(
|
||||
request,
|
||||
crate::api::limits::LimitType::Guild,
|
||||
limits_instance,
|
||||
limits_user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => result,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let result_text = result.text().await.unwrap();
|
||||
match from_str::<types::Channel>(&result_text) {
|
||||
Ok(object) => Ok(object),
|
||||
Err(e) => Err(InstanceServerError::RequestErrorError {
|
||||
url: format!("{}/channels/{}/", url_api, channel_id),
|
||||
error: e.to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -198,37 +198,4 @@ impl types::Channel {
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get(
|
||||
token: &str,
|
||||
url_api: &str,
|
||||
channel_id: &str,
|
||||
limits_user: &mut Limits,
|
||||
limits_instance: &mut Limits,
|
||||
) -> Result<types::Channel, InstanceServerError> {
|
||||
let request = Client::new()
|
||||
.get(format!("{}/channels/{}/", url_api, channel_id))
|
||||
.bearer_auth(token);
|
||||
let mut requester = LimitedRequester::new().await;
|
||||
let result = match requester
|
||||
.send_request(
|
||||
request,
|
||||
crate::api::limits::LimitType::Guild,
|
||||
limits_instance,
|
||||
limits_user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => result,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let result_text = result.text().await.unwrap();
|
||||
match from_str::<types::Channel>(&result_text) {
|
||||
Ok(object) => Ok(object),
|
||||
Err(e) => Err(InstanceServerError::RequestErrorError {
|
||||
url: format!("{}/channels/{}/", url_api, channel_id),
|
||||
error: e.to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue