iop_client/
photobank.rs

1use std::collections::HashMap;
2
3use log::info;
4
5use crate::{
6    constants::{methods, urls},
7    model, IopClient,
8};
9
10impl IopClient {
11    /// 图片银行分组信息获取
12    ///
13    /// [官方文档](https://open.alibaba.com/doc/api.htm#/api?cid=20966&path=alibaba.icbu.photobank.group.list&methodType=GET/POST)
14    ///
15    /// Lists all photo bank groups, or a specific photo bank group by its identifier.
16    ///
17    /// The photo bank groups are ordered by parent_id and then id in descending order.
18    ///
19    /// # Arguments
20    ///
21    /// * `id` - The identifier of the photo bank group to retrieve. If `None`, all groups are retrieved.
22    ///
23    /// # Returns
24    ///
25    /// A `Result` containing a vector of `PhotoAlbumGroup` models if successful, or an error if the process fails.
26    pub async fn list_photo_bank_groups(
27        &self,
28        id: Option<i32>,
29    ) -> Result<Vec<model::PhotoAlbumGroup>, Box<dyn std::error::Error>> {
30        let mut map = HashMap::new();
31        if let Some(value) = id {
32            map.insert("group_id".to_string(), format!("{}", value));
33        }
34        map.insert(
35            "method".to_string(),
36            methods::ALIBABA_ICBU_PHOTOBANK_GROUP_LIST.to_string(),
37        );
38        let params = self.build_request_params(map).await;
39
40        let hash = self.generate_sign(None, params.clone());
41        let url = self.generate_url(urls::BASE_SYNC_URL.to_string(), params.clone(), hash);
42        info!("--------list_photo_bank_groups-------- url: {:#?}", url);
43
44        let response = self.client.get(&url).send().await?;
45        let result = response.json::<model::PhotobankGroupListResponse>().await?;
46
47        Ok(result.alibaba_icbu_photobank_group_list_response.groups)
48    }
49}