tencent_sdk/services/
tag.rs

1use crate::client::TencentCloudClient;
2use serde_json::{json, Value};
3use std::error::Error;
4
5/// 查看标签项目列表 - DescribeProjects
6///
7/// **接口描述**:
8/// - 接口请求域名:tag.tencentcloudapi.com
9/// - 默认接口请求频率限制:20次/秒
10///
11/// **入参说明**:
12///
13/// | 参数    | 类型              | 说明                                                     |
14/// |---------|-------------------|----------------------------------------------------------|
15/// | Action  | String            | 固定为 `"DescribeProjects"`                              |
16/// | Version | String            | 固定为 `"2018-08-13"`                                    |
17/// | AllList | Option<Integer>   | 可选,默认值为 `1`,表示获取所有项目                      |
18/// | Limit   | Option<Integer>   | 可选,默认值为 `1000`,返回项目数量上限                  |
19/// | Offset  | Option<Integer>   | 可选,默认值为 `0`,偏移量                               |
20/// | Body    | JSON              | 由上述参数构成的 JSON 字符串                              |
21///
22/// **出参说明**:
23///
24/// | 字段       | 类型    | 说明                                            |
25/// |------------|---------|-------------------------------------------------|
26/// | TotalCount | Integer | 符合条件的项目总数                              |
27/// | ProjectSet | Array   | 标签项目列表,包含每个项目的详细信息              |
28/// | RequestId  | String  | 唯一请求ID,用于问题定位                        |
29pub async fn describe_projects(
30    client: &TencentCloudClient,
31    all_list: Option<i32>,
32    limit: Option<i32>,
33    offset: Option<i32>,
34) -> Result<Value, Box<dyn Error>> {
35    let payload = json!({
36        "AllList": all_list.unwrap_or(1),
37        "Limit": limit.unwrap_or(1000),
38        "Offset": offset.unwrap_or(0)
39    })
40    .to_string();
41
42    client
43        .request(
44            "tag",
45            "tag.tencentcloudapi.com",
46            None,
47            "2018-08-13",
48            "DescribeProjects",
49            &payload,
50        )
51        .await
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57    use tokio;
58
59    const TEST_SECRET_ID: &str = "YourSecretId";
60    const TEST_SECRET_KEY: &str = "YourSecretKey";
61
62    #[tokio::test]
63    async fn test_describe_projects_default() {
64        let client = TencentCloudClient::new(TEST_SECRET_ID, TEST_SECRET_KEY, None);
65        match describe_projects(&client, None, None, None).await {
66            Ok(resp) => {
67                println!("DescribeProjects 响应:\n{}", resp);
68                assert!(!resp.is_null());
69            }
70            Err(e) => eprintln!("调用 DescribeProjects 时出错: {}", e),
71        }
72    }
73}