Skip to main content

openlark_docs/common/api_endpoints/
base.rs

1//! Base API V2 端点枚举
2//!
3//! 提供 Base v2 的端点定义,支持 method、path 和认证要求的统一管理(#438 tracer)。
4
5use super::CatalogEndpoint;
6use openlark_core::api::HttpMethod;
7
8/// Base API V2 端点枚举
9#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(test, derive(strum_macros::EnumIter))]
11pub enum BaseApiV2 {
12    /// 新增自定义角色
13    RoleCreate(String),
14    /// 更新自定义角色
15    RoleUpdate(String, String),
16    /// 列出自定义角色
17    RoleList(String),
18}
19
20impl BaseApiV2 {
21    /// 生成对应的 URL
22    pub fn to_url(&self) -> String {
23        match self {
24            BaseApiV2::RoleCreate(app_token) => {
25                format!("/open-apis/base/v2/apps/{app_token}/roles")
26            }
27            BaseApiV2::RoleUpdate(app_token, role_id) => {
28                format!("/open-apis/base/v2/apps/{app_token}/roles/{role_id}")
29            }
30            BaseApiV2::RoleList(app_token) => {
31                format!("/open-apis/base/v2/apps/{app_token}/roles")
32            }
33        }
34    }
35}
36
37impl CatalogEndpoint for BaseApiV2 {
38    fn to_url(&self) -> String {
39        // delegate to inherent for backward compat with direct .to_url() calls
40        BaseApiV2::to_url(self)
41    }
42
43    fn method(&self) -> HttpMethod {
44        match self {
45            BaseApiV2::RoleCreate(_) => HttpMethod::Post,
46            BaseApiV2::RoleUpdate(_, _) => HttpMethod::Put,
47            BaseApiV2::RoleList(_) => HttpMethod::Get,
48        }
49    }
50
51    // to_request 和 supported_access_token_types 使用 trait 默认实现
52}