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 #[cfg(feature = "spark")]
67 pub fn spark(&self) -> crate::spark::SparkService {
68 crate::spark::SparkService::new(self.config.clone())
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use crate::{PlatformConfig, PlatformService};
75
76 #[test]
77 fn test_service_creation() {
78 let config = PlatformConfig::builder()
79 .app_id("test_app_id")
80 .app_secret("test_app_secret")
81 .build();
82 let service = PlatformService::new(config);
83 assert!(service.is_ok());
84 }
85}