use std::{num::NonZeroU32, time::Duration};
use s2_sdk::{
S2,
types::{AccountEndpoint, BasinEndpoint, RetryConfig, S2Config, S2Endpoints},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
{
let token = "local-token".to_string();
let endpoints = S2Endpoints::new(
AccountEndpoint::new("http://localhost:8080")?,
BasinEndpoint::new("http://localhost:8080")?,
)?;
let client = S2::new(S2Config::new(token).with_endpoints(endpoints))?;
println!("Created client with custom endpoints: {:?}", client);
}
{
let token = std::env::var("S2_ACCESS_TOKEN").unwrap_or_else(|_| "demo".into());
let client = S2::new(
S2Config::new(token).with_retry(
RetryConfig::new()
.with_max_attempts(NonZeroU32::new(5).unwrap())
.with_min_base_delay(Duration::from_millis(100))
.with_max_base_delay(Duration::from_secs(2)),
),
)?;
println!("Created client with retry config: {:?}", client);
}
{
let token = std::env::var("S2_ACCESS_TOKEN").unwrap_or_else(|_| "demo".into());
let client = S2::new(
S2Config::new(token)
.with_connection_timeout(Duration::from_secs(5))
.with_request_timeout(Duration::from_secs(10)),
)?;
println!("Created client with timeout config: {:?}", client);
}
Ok(())
}