Skip to content

Commit

Permalink
Add Invite::url(), RichInvite::url()
Browse files Browse the repository at this point in the history
Add helper methods to easily produce invite URLs, such as
`"https://discord.gg/WxZumR"`.
  • Loading branch information
Zeyla Hellyer committed May 22, 2017
1 parent 6502ded commit 3062981
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/model/invite.rs
Expand Up @@ -103,6 +103,36 @@ impl Invite {
pub fn get(code: &str, stats: bool) -> Result<Invite> {
rest::get_invite(utils::parse_invite(code), stats)
}

/// Returns a URL to use for the invite.
///
/// # Examples
///
/// Retrieve the URL for an invite with the code `WxZumR`:
///
/// ```rust
/// # use serenity::model::*;
/// #
/// # let invite = Invite {
/// # code: "WxZumR".to_owned(),
/// # channel: InviteChannel {
/// # id: ChannelId(1),
/// # name: "foo".to_owned(),
/// # kind: ChannelType::Text,
/// # },
/// # guild: InviteGuild {
/// # id: GuildId(2),
/// # icon: None,
/// # name: "bar".to_owned(),
/// # splash_hash: None,
/// # },
/// # };
/// #
/// assert_eq!(invite.url(), "https://discord.gg/WxZumR");
/// ```
pub fn url(&self) -> String {
format!("https://discord.gg/{}", self.code)
}
}

/// A inimal information about the channel an invite points to.
Expand Down Expand Up @@ -240,4 +270,46 @@ impl RichInvite {

rest::delete_invite(&self.code)
}

/// Returns a URL to use for the invite.
///
/// # Examples
///
/// Retrieve the URL for an invite with the code `WxZumR`:
///
/// ```rust
/// # use serenity::model::*;
/// #
/// # let invite = RichInvite {
/// # code: "WxZumR".to_owned(),
/// # channel: InviteChannel {
/// # id: ChannelId(1),
/// # name: "foo".to_owned(),
/// # kind: ChannelType::Text,
/// # },
/// # created_at: "bar".to_owned(),
/// # guild: InviteGuild {
/// # id: GuildId(2),
/// # icon: None,
/// # name: "baz".to_owned(),
/// # splash_hash: None,
/// # },
/// # inviter: User {
/// # avatar: None,
/// # bot: false,
/// # discriminator: 3,
/// # id: UserId(4),
/// # name: "qux".to_owned(),
/// # },
/// # max_age: 5,
/// # max_uses: 6,
/// # temporary: true,
/// # uses: 7,
/// # };
/// #
/// assert_eq!(invite.url(), "https://discord.gg/WxZumR");
/// ```
pub fn url(&self) -> String {
format!("https://discord.gg/{}", self.code)
}
}

0 comments on commit 3062981

Please sign in to comment.