openlark_client/traits/
client.rs1use openlark_core::config::Config as CoreConfig;
6use std::time::Duration;
7
8pub trait LarkClient: Send + Sync {
18 fn config(&self) -> &CoreConfig;
20
21 fn is_configured(&self) -> bool {
26 !self.config().app_id().is_empty() && !self.config().app_secret().is_empty()
27 }
28
29 fn app_id(&self) -> &str {
31 self.config().app_id()
32 }
33
34 fn app_secret(&self) -> &str {
36 self.config().app_secret()
37 }
38
39 fn base_url(&self) -> &str {
41 self.config().base_url()
42 }
43
44 fn timeout(&self) -> Option<Duration> {
46 self.config().req_timeout()
47 }
48
49 fn retry_count(&self) -> u32 {
51 self.config().retry_count()
52 }
53
54 fn is_log_enabled(&self) -> bool {
56 self.config().enable_log()
57 }
58}
59
60#[cfg(test)]
61#[allow(unused_imports)]
62mod tests {
63 use super::*;
64 use openlark_core::config::Config;
65
66 struct TestClient {
67 config: Config,
68 }
69
70 impl LarkClient for TestClient {
71 fn config(&self) -> &Config {
72 &self.config
73 }
74 }
75
76 #[test]
77 fn test_lark_client_basic_methods() {
78 let config = Config::builder()
79 .app_id("test_app_id")
80 .app_secret("test_app_secret")
81 .base_url("https://test.feishu.cn")
82 .req_timeout(std::time::Duration::from_secs(30))
83 .retry_count(3)
84 .enable_log(true)
85 .build();
86
87 let client = TestClient { config };
88
89 assert_eq!(client.app_id(), "test_app_id");
90 assert_eq!(client.app_secret(), "test_app_secret");
91 assert_eq!(client.base_url(), "https://test.feishu.cn");
92 assert_eq!(client.timeout(), Some(std::time::Duration::from_secs(30)));
93 assert_eq!(client.retry_count(), 3);
94 assert!(client.is_log_enabled());
95 assert!(client.is_configured());
96 }
97
98 #[test]
99 fn test_not_configured_client() {
100 let config = Config::default();
101
102 let client = TestClient { config };
103 assert!(!client.is_configured());
104 }
105}