use crate::api::resources::ForumClient;
use crate::{ApiError, ClientConfig};
use std::collections::HashMap;
use std::time::Duration;
pub struct ApiClientBuilder {
config: ClientConfig,
}
impl ApiClientBuilder {
pub fn new(base_url: impl Into<String>) -> Self {
let mut config = ClientConfig::default();
config.base_url = base_url.into();
Self { config }
}
pub fn api_key(mut self, key: impl Into<String>) -> Self {
self.config.api_key = Some(key.into());
self
}
pub fn token(mut self, token: impl Into<String>) -> Self {
self.config.token = Some(token.into());
self
}
pub fn username(mut self, username: impl Into<String>) -> Self {
self.config.username = Some(username.into());
self
}
pub fn password(mut self, password: impl Into<String>) -> Self {
self.config.password = Some(password.into());
self
}
pub fn timeout(mut self, timeout: Duration) -> Self {
self.config.timeout = timeout;
self
}
pub fn max_retries(mut self, retries: u32) -> Self {
self.config.max_retries = retries;
self
}
pub fn custom_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.config.custom_headers.insert(key.into(), value.into());
self
}
pub fn custom_headers(mut self, headers: HashMap<String, String>) -> Self {
self.config.custom_headers.extend(headers);
self
}
pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.config.user_agent = user_agent.into();
self
}
pub fn build(self) -> Result<ForumClient, ApiError> {
ForumClient::new(self.config)
}
}