Skip to main content

soundcloud_rs/client/
builder.rs

1use crate::models::client::Client;
2use crate::models::config::RetryConfig;
3use crate::models::error::Error;
4
5#[derive(Debug)]
6pub struct ClientBuilder {
7    retry_config: RetryConfig,
8}
9
10impl ClientBuilder {
11    /// Create a new ClientBuilder with default retry configuration.
12    pub fn new() -> Self {
13        Self {
14            retry_config: RetryConfig::default(),
15        }
16    }
17
18    /// Set the maximum number of retry attempts.
19    pub fn with_max_retries(mut self, max_retries: u32) -> Self {
20        self.retry_config.max_retries = max_retries;
21        self
22    }
23
24    /// Enable or disable retrying on 401 Unauthorized responses.
25    pub fn with_retry_on_401(mut self, retry_on_401: bool) -> Self {
26        self.retry_config.retry_on_401 = retry_on_401;
27        self
28    }
29
30    /// Build the Client with the configured settings.
31    pub async fn build(self) -> Result<Client, Error> {
32        Client::with_retry_config(self.retry_config).await
33    }
34}
35
36impl Default for ClientBuilder {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41