openlark_platform/
service.rs1use crate::PlatformConfig;
6use openlark_core::SDKResult;
7use std::sync::Arc;
8
9#[derive(Debug, Clone)]
13pub struct PlatformService {
14 config: Arc<PlatformConfig>,
16}
17
18impl PlatformService {
19 pub fn new(config: PlatformConfig) -> SDKResult<Self> {
29 Ok(Self {
30 config: Arc::new(config),
31 })
32 }
33
34 pub fn config(&self) -> Arc<PlatformConfig> {
36 self.config.clone()
37 }
38
39 #[cfg(feature = "app-engine")]
43 pub fn app_engine(&self) -> crate::app_engine::AppEngineService {
44 crate::app_engine::AppEngineService::new(self.config.clone())
45 }
46
47 #[cfg(feature = "directory")]
51 pub fn directory(&self) -> crate::directory::DirectoryService {
52 crate::directory::DirectoryService::new(self.config.clone())
53 }
54
55 #[cfg(feature = "admin")]
59 pub fn admin(&self) -> crate::admin::AdminService {
60 crate::admin::AdminService::new(self.config.clone())
61 }
62}
63
64#[cfg(test)]
65mod tests {
66 use crate::{PlatformConfig, PlatformService};
67
68 #[test]
69 fn test_service_creation() {
70 let config = PlatformConfig::builder()
71 .app_id("test_app_id")
72 .app_secret("test_app_secret")
73 .build();
74 let service = PlatformService::new(config);
75 assert!(service.is_ok());
76 }
77}