Implement send_friend_request
This commit is contained in:
parent
6dfb0610ec
commit
c2d46196c8
|
@ -1,6 +1,12 @@
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use serde_json::to_string;
|
||||||
|
|
||||||
use crate::{api::deserialize_response, errors::ChorusLibError, instance::UserMeta, types};
|
use crate::{
|
||||||
|
api::{deserialize_response, handle_request_as_option},
|
||||||
|
errors::ChorusLibError,
|
||||||
|
instance::UserMeta,
|
||||||
|
types,
|
||||||
|
};
|
||||||
|
|
||||||
impl UserMeta {
|
impl UserMeta {
|
||||||
/// Retrieves the mutual relationships between the authenticated user and the specified user.
|
/// Retrieves the mutual relationships between the authenticated user and the specified user.
|
||||||
|
@ -30,4 +36,24 @@ impl UserMeta {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sends a friend request to a user.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `schema` - A [`FriendRequestSendSchema`] struct that holds the information about the friend request to be sent.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// This function returns an [`Option`] that holds a [`ChorusLibError`] if the request fails.
|
||||||
|
pub async fn send_friend_request(
|
||||||
|
&mut self,
|
||||||
|
schema: types::FriendRequestSendSchema,
|
||||||
|
) -> Option<ChorusLibError> {
|
||||||
|
let belongs_to = self.belongs_to.borrow();
|
||||||
|
let url = format!("{}/users/@me/relationships/", belongs_to.urls.get_api());
|
||||||
|
drop(belongs_to);
|
||||||
|
let body = to_string(&schema).unwrap();
|
||||||
|
let request = Client::new().post(url).bearer_auth(self.token()).body(body);
|
||||||
|
handle_request_as_option(request, self, crate::api::limits::LimitType::Global).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue