openlark_client/traits/
client.rs1use crate::Config;
6use std::time::Duration;
7
8pub trait LarkClient: Send + Sync {
18 fn config(&self) -> &Config;
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) -> Duration {
46 self.config().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 std::time::Duration;
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 {
79 app_id: "test_app_id".to_string(),
80 app_secret: "test_app_secret".to_string(),
81 app_type: openlark_core::constants::AppType::SelfBuild,
82 enable_token_cache: true,
83 base_url: "https://test.feishu.cn".to_string(),
84 timeout: Duration::from_secs(30),
85 retry_count: 3,
86 enable_log: true,
87 headers: std::collections::HashMap::new(),
88 core_config: None,
89 };
90
91 let client = TestClient { config };
92
93 assert_eq!(client.app_id(), "test_app_id");
94 assert_eq!(client.app_secret(), "test_app_secret");
95 assert_eq!(client.base_url(), "https://test.feishu.cn");
96 assert_eq!(client.timeout(), Duration::from_secs(30));
97 assert_eq!(client.retry_count(), 3);
98 assert!(client.is_log_enabled());
99 assert!(client.is_configured());
100 }
101
102 #[test]
103 fn test_not_configured_client() {
104 let config = Config {
105 app_id: String::new(),
106 app_secret: String::new(),
107 ..Default::default()
108 };
109
110 let client = TestClient { config };
111 assert!(!client.is_configured());
112 }
113}