rust-cnb 0.1.2

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

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

/// Contributors API 客户端
pub struct ContributorsClient {
    base_url: String,
    client: Client,
}

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

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

    /// 获取指定组织或仓库内, 访问成员在当前层级内的权限信息。Get permission information for accessing members at current level.
    pub async fn get_group_members_access_level(
        &self,
        group: String,
        include_inherit: Option<bool>,
    ) -> Result<Value> {
        let path = format!("/{}/-/members/access-level", group);
        let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
        
        if let Some(value) = include_inherit {
            url.query_pairs_mut().append_pair("include_inherit", &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()))
        }
    }

    /// 获取指定组织或仓库内指定成员的权限信息, 结果按组织层级来展示, 包含上层组织的权限继承信息。Get specified member&#x27;s permissions with organizational hierarchy.
    pub async fn get_repo_members_username_access_level(
        &self,
        repo: String,
        username: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/members/{}/access-level", repo, username);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                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()))
        }
    }

    /// 获取指定组织或仓库内, 访问成员在当前层级内的权限信息。Get permission information for accessing members at current level.
    pub async fn get_repo_members_access_level(
        &self,
        repo: String,
        include_inherit: Option<bool>,
    ) -> Result<Value> {
        let path = format!("/{}/-/members/access-level", repo);
        let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
        
        if let Some(value) = include_inherit {
            url.query_pairs_mut().append_pair("include_inherit", &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()))
        }
    }

    /// 获取指定组织或仓库内指定成员的权限信息, 结果按组织层级来展示, 包含上层组织的权限继承信息。Get specified member&#x27;s permissions with organizational hierarchy.
    pub async fn get_group_members_username_access_level(
        &self,
        group: String,
        username: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/members/{}/access-level", group, username);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                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()))
        }
    }

}