Skip to content

Commit

Permalink
Fix HttpBuilder constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Nov 20, 2024
1 parent 918340a commit 8277ca4
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ where
/// # }
/// ```
#[must_use]
#[derive(Default)]
pub struct HttpBuilder {
client: Option<Client>,
ratelimiter: Option<Ratelimiter>,
Expand All @@ -86,8 +85,32 @@ pub struct HttpBuilder {

impl HttpBuilder {
/// Construct a new builder.
pub fn new() -> Self {
Self::default()
pub fn new(token: Token) -> Self {
Self {
client: None,
ratelimiter: None,
ratelimiter_disabled: false,
token: Some(token),
proxy: None,
application_id: None,
default_allowed_mentions: None,
}
}

/// Construct a new builder without a token set.
///
/// Most Discord functionality requires a logged-in Bot token, but there are some exceptions
/// such as webhook endpoints.
pub fn without_token() -> Self {
Self {
client: None,
ratelimiter: None,
ratelimiter_disabled: false,
token: None,
proxy: None,
application_id: None,
default_allowed_mentions: None,
}
}

/// Sets the application_id to use interactions.
Expand All @@ -96,12 +119,6 @@ impl HttpBuilder {
self
}

/// Sets an authorization token for the bot.
pub fn token(mut self, token: Token) -> Self {
self.token = Some(token);
self
}

/// Sets the [`reqwest::Client`]. If one isn't provided, a default one will be used.
pub fn client(mut self, client: Client) -> Self {
self.client = Some(client);
Expand Down Expand Up @@ -227,14 +244,16 @@ impl Http {
/// Construct an authorized HTTP client.
#[must_use]
pub fn new(token: Token) -> Self {
HttpBuilder::new().token(token).build()
HttpBuilder::new(token).build()
}

/// Construct an unauthorized HTTP client, with no token. Few things will work, but webhooks
/// are one exception.
/// Construct an unauthorized HTTP client, with no token.
///
/// Most Discord functionality requires a logged-in Bot token, but there are some exceptions
/// such as webhook endpoints.
#[must_use]
pub fn without_token() -> Self {
HttpBuilder::new().build()
HttpBuilder::without_token().build()
}

pub fn application_id(&self) -> Option<ApplicationId> {
Expand Down

0 comments on commit 8277ca4

Please sign in to comment.