Skip to content

Commit

Permalink
Implement endpoints for getting emojis of a guild (#937)
Browse files Browse the repository at this point in the history
* Add http methods to retrieve emojis

* Add model counterparts of the http methods
  • Loading branch information
arqunis authored Aug 22, 2020
1 parent a9c9caa commit 2a1c385
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,24 @@ impl Http {
}).await
}

/// Gets all emojis of a guild.
pub async fn get_emojis(&self, guild_id: u64) -> Result<Vec<Emoji>> {
self.fire(Request {
body: None,
headers: None,
route: RouteInfo::GetEmojis { guild_id },
}).await
}

/// Gets information about an emoji in a guild.
pub async fn get_emoji(&self, guild_id: u64, emoji_id: u64) -> Result<Emoji> {
self.fire(Request {
body: None,
headers: None,
route: RouteInfo::GetEmoji { guild_id, emoji_id },
}).await
}

/// Gets current gateway.
pub async fn get_gateway(&self) -> Result<Gateway> {
self.fire(Request {
Expand Down
17 changes: 17 additions & 0 deletions src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,13 @@ pub enum RouteInfo<'a> {
},
GetCurrentApplicationInfo,
GetCurrentUser,
GetEmojis {
guild_id: u64,
},
GetEmoji {
guild_id: u64,
emoji_id: u64,
},
GetGateway,
GetGuild {
guild_id: u64,
Expand Down Expand Up @@ -1251,6 +1258,16 @@ impl<'a> RouteInfo<'a> {
Route::UsersMe,
Cow::from(Route::user("@me")),
),
RouteInfo::GetEmojis { guild_id } => (
LightMethod::Get,
Route::GuildsIdEmojis(guild_id),
Cow::from(Route::guild_emojis(guild_id)),
),
RouteInfo::GetEmoji { guild_id, emoji_id } => (
LightMethod::Get,
Route::GuildsIdEmojisId(guild_id),
Cow::from(Route::guild_emoji(guild_id, emoji_id)),
),
RouteInfo::GetGateway => (
LightMethod::Get,
Route::Gateway,
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,22 @@ impl GuildId {
http.as_ref().get_guild(self.0).await
}

/// Gets all [`Emoji`]s of this guild via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>> {
http.as_ref().get_emojis(self.0).await
}

/// Gets an [`Emoji`] of this guild by its ID via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emoji(&self, http: impl AsRef<Http>, emoji_id: EmojiId) -> Result<Emoji> {
http.as_ref().get_emoji(self.0, emoji_id.0).await
}

/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,22 @@ impl Guild {
.map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}

/// Gets all [`Emoji`]s of this guild via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>> {
self.id.emojis(http).await
}

/// Gets an [`Emoji`] of this guild by its ID via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emoji(&self, http: impl AsRef<Http>, emoji_id: EmojiId) -> Result<Emoji> {
self.id.emoji(http, emoji_id).await
}

/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,22 @@ impl PartialGuild {
.map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}

/// Gets all [`Emoji`]s of this guild via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>> {
self.id.emojis(http).await
}

/// Gets an [`Emoji`] of this guild by its ID via HTTP.
///
/// [`Emoji`]: struct.Emoji.html
#[inline]
pub async fn emoji(&self, http: impl AsRef<Http>, emoji_id: EmojiId) -> Result<Emoji> {
self.id.emoji(http, emoji_id).await
}

/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
Expand Down

0 comments on commit 2a1c385

Please sign in to comment.