refluxer 0.1.0

Rust API wrapper for Fluxer
Documentation
use crate::error::HttpError;
use crate::http::client::HttpClient;
use crate::http::routing::Route;
use crate::model::channel::Channel;
use crate::model::id::UserId;
use crate::model::user::User;

impl HttpClient {
    pub async fn get_current_user(&self) -> Result<User, HttpError> {
        self.request_no_body(Route::GetCurrentUser).await
    }
    pub async fn get_user(&self, user_id: UserId) -> Result<User, HttpError> {
        self.request_no_body(Route::GetUser { user_id }).await
    }
    pub async fn modify_current_user(&self, params: &ModifyCurrentUser) -> Result<User, HttpError> {
        self.request(Route::ModifyCurrentUser, Some(params)).await
    }
    /// Open a DM channel with a user. Returns an existing channel if one exists.
    pub async fn create_dm(&self, recipient_id: UserId) -> Result<Channel, HttpError> {
        #[derive(serde::Serialize)]
        struct Body {
            recipient_id: UserId,
        }
        self.request(Route::CreateDm, Some(&Body { recipient_id }))
            .await
    }

    /// Create a group DM with multiple recipients (max 9).
    pub async fn create_group_dm(&self, recipients: &[UserId]) -> Result<Channel, HttpError> {
        #[derive(serde::Serialize)]
        struct Body<'a> {
            recipients: &'a [UserId],
        }
        self.request(Route::CreateDm, Some(&Body { recipients }))
            .await
    }

    /// List the current user's DM and group DM channels.
    pub async fn list_private_channels(&self) -> Result<Vec<Channel>, HttpError> {
        self.request_no_body(Route::ListPrivateChannels).await
    }

    /// Fetch the extended profile of another user (bio, banner, mutual
    /// guilds, badges, etc.). The response shape is large and has many
    /// optional fields, so it is returned as `serde_json::Value`.
    pub async fn get_user_profile(
        &self,
        target_id: UserId,
    ) -> Result<serde_json::Value, HttpError> {
        self.request_no_body(Route::GetUserProfile { target_id })
            .await
    }

    /// List messages in which the current user was mentioned.
    pub async fn list_current_user_mentions(
        &self,
    ) -> Result<Vec<crate::model::message::Message>, HttpError> {
        self.request_no_body(Route::ListCurrentUserMentions).await
    }

    /// Dismiss a mention from the current user's mention list.
    pub async fn delete_current_user_mention(
        &self,
        message_id: crate::model::id::MessageId,
    ) -> Result<(), HttpError> {
        self.request_empty(Route::DeleteCurrentUserMention { message_id }, None::<&()>)
            .await
    }
}

#[derive(Debug, Default, serde::Serialize)]
pub struct ModifyCurrentUser {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub global_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bio: Option<String>,
}