rust-cnb 0.1.2

[DEPRECATED - use `cnb` crate instead] rust-cnb with Generated API client
Documentation
//! RepoLabels API 客户端

use crate::error::{ApiError, Result};
use reqwest::Client;
use serde_json::Value;
use url::Url;

/// RepoLabels API 客户端
pub struct RepoLabelsClient {
    base_url: String,
    client: Client,
}

impl RepoLabelsClient {
    /// 创建新的 RepoLabels API 客户端
    pub fn new(base_url: String, client: Client) -> Self {
        Self { base_url, client }
    }

    /// 设置认证信息
    pub fn with_auth(self, token: &str) -> Self {
        // 这里可以扩展认证逻辑
        self
    }

    /// 查询仓库的标签(label) 列表。List repository labels.
    pub async fn get_repo_labels(
        &self,
        repo: String,
        page: Option<i64>,
        page_size: Option<i64>,
        keyword: Option<String>,
    ) -> Result<Value> {
        let path = format!("/{}/-/labels", repo);
        let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
        
        if let Some(value) = page {
            url.query_pairs_mut().append_pair("page", &value.to_string());
        }
        if let Some(value) = page_size {
            url.query_pairs_mut().append_pair("page_size", &value.to_string());
        }
        if let Some(value) = keyword {
            url.query_pairs_mut().append_pair("keyword", &value.to_string());
        }

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 创建一个 标签。Create a label.
    pub async fn post_repo_labels(
        &self,
        repo: String,
        post_label_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/labels", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::POST,
            url
        );



        request = request.json(&post_label_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 删除指定的仓库标签 label。Delete the specified repository label.
    pub async fn delete_repo_labels_name(
        &self,
        repo: String,
        name: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/labels/{}", repo, name);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::DELETE,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 更新标签信息。Update label information.
    pub async fn patch_repo_labels_name(
        &self,
        repo: String,
        name: String,
        patch_label_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/labels/{}", repo, name);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::PATCH,
            url
        );



        request = request.json(&patch_label_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

}