Skip to main content

openlark_platform/directory/
mod.rs

1//! 目录服务模块
2//!
3//! 提供用户搜索、组织目录、人员查找等功能 (21 APIs)
4
5use crate::PlatformConfig;
6use std::sync::Arc;
7
8/// 目录服务
9///
10/// 提供目录服务相关 API 的访问入口。
11#[derive(Debug, Clone)]
12pub struct DirectoryService {
13    /// 客户端配置
14    config: Arc<PlatformConfig>,
15}
16
17impl DirectoryService {
18    /// 创建新的目录服务实例
19    pub fn new(config: Arc<PlatformConfig>) -> Self {
20        Self { config }
21    }
22
23    /// 获取客户端配置
24    pub fn config(&self) -> Arc<PlatformConfig> {
25        self.config.clone()
26    }
27
28    /// V1 版本 API
29    #[cfg(feature = "v1")]
30    pub fn v1(&self) -> crate::directory::directory::v1::DirectoryV1 {
31        crate::directory::directory::v1::DirectoryV1::new(self.config.clone())
32    }
33}
34
35#[cfg(feature = "v1")]
36pub mod directory;
37
38#[cfg(test)]
39mod tests {
40    use crate::{PlatformConfig, directory::DirectoryService};
41
42    #[test]
43    fn test_service_creation() {
44        let config = PlatformConfig::builder()
45            .app_id("test_app_id")
46            .app_secret("test_app_secret")
47            .build();
48
49        let service = DirectoryService::new(std::sync::Arc::new(config));
50        // PlatformConfig 实现了 Deref,可以直接访问 app_id
51        assert_eq!(service.config().app_id(), "test_app_id");
52    }
53}