1pub mod error;
25pub mod session;
26pub mod types;
27pub mod webhook;
28
29pub use error::WiError;
30pub use session::Session;
31
32use std::sync::Arc;
33use std::time::Duration;
34
35const DEFAULT_BASE_URL: &str = "https://endpoint.wi.api.br";
36
37#[derive(Clone)]
39pub struct Wi {
40 http: Arc<reqwest::Client>,
41 base_url: Arc<String>,
42 api_key: Arc<String>,
43}
44
45impl Wi {
46 pub fn new(api_key: impl Into<String>) -> Self {
48 Self::builder(api_key).build()
49 }
50
51 pub fn builder(api_key: impl Into<String>) -> WiBuilder {
53 WiBuilder {
54 api_key: api_key.into(),
55 base_url: DEFAULT_BASE_URL.to_string(),
56 timeout: Duration::from_secs(30),
57 }
58 }
59
60 pub fn session(&self, id: impl Into<String>) -> Session {
62 Session {
63 id: id.into(),
64 http: self.http.clone(),
65 base_url: self.base_url.clone(),
66 api_key: self.api_key.clone(),
67 }
68 }
69}
70
71pub struct WiBuilder {
73 api_key: String,
74 base_url: String,
75 timeout: Duration,
76}
77
78impl WiBuilder {
79 pub fn base_url(mut self, url: impl Into<String>) -> Self {
81 self.base_url = url.into().trim_end_matches('/').to_string();
82 self
83 }
84
85 pub fn timeout(mut self, d: Duration) -> Self {
87 self.timeout = d;
88 self
89 }
90
91 pub fn build(self) -> Wi {
92 let http = reqwest::Client::builder()
93 .timeout(self.timeout)
94 .build()
95 .expect("failed to build HTTP client");
96
97 Wi {
98 http: Arc::new(http),
99 base_url: Arc::new(self.base_url),
100 api_key: Arc::new(self.api_key),
101 }
102 }
103}