-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): add get guild role endpoint (#2394)
Discord supports an endpoint that allows to fetch a single guild role. - discord/discord-api-docs#7074
- Loading branch information
Showing
5 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, TryIntoRequest}, | ||
response::{Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
guild::Role, | ||
id::{ | ||
marker::{GuildMarker, RoleMarker}, | ||
Id, | ||
}, | ||
}; | ||
|
||
/// Get a role of a guild. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct GetRole<'a> { | ||
guild_id: Id<GuildMarker>, | ||
role_id: Id<RoleMarker>, | ||
http: &'a Client, | ||
} | ||
|
||
impl<'a> GetRole<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
guild_id: Id<GuildMarker>, | ||
role_id: Id<RoleMarker>, | ||
) -> Self { | ||
Self { | ||
guild_id, | ||
role_id, | ||
http, | ||
} | ||
} | ||
} | ||
|
||
impl IntoFuture for GetRole<'_> { | ||
type Output = Result<Response<Role>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<Role>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for GetRole<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok(Request::from_route(&Route::GetRole { | ||
guild_id: self.guild_id.get(), | ||
role_id: self.role_id.get(), | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
mod create_role; | ||
mod delete_role; | ||
mod get_guild_roles; | ||
mod get_role; | ||
mod update_role; | ||
mod update_role_positions; | ||
|
||
pub use self::{ | ||
create_role::CreateRole, delete_role::DeleteRole, get_guild_roles::GetGuildRoles, | ||
update_role::UpdateRole, update_role_positions::UpdateRolePositions, | ||
get_role::GetRole, update_role::UpdateRole, update_role_positions::UpdateRolePositions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters