cnb 0.2.0

CNB (cnb.cool) API client for Rust — typed, async, production-ready
Documentation
// @generated DO NOT EDIT.
//
// Generated from the CNB OpenAPI specification by `cnb-codegen`.
// Run `cargo run -p cnb-codegen --manifest-path codegen/Cargo.toml \
//      -- --spec codegen/spec/swagger.json --out src` to refresh.

#![allow(clippy::all)]
#![allow(missing_docs)]
#![allow(unused_imports)]
#![allow(unused_mut)]

use reqwest::Method;
use serde::Serialize;

use crate::error::{ApiError, Result};
use crate::http::HttpInner;
use crate::models;

// `Starring` resource client (generated, 3 operations).

/// Resource client.
#[derive(Debug, Clone)]
pub struct StarringClient {
    inner: HttpInner,
}

impl StarringClient {
    /// Construct a new resource client. Normally obtained
    /// via [`crate::ApiClient`] rather than directly.
    pub fn new(inner: HttpInner) -> Self {
        Self { inner }
    }

    /// 获取当前用户 star 的仓库列表。List all stared repositories.
    ///
    /// `GET /user/stared-repos`
    pub async fn get_user_all_stared_repos(
        &self,
        query: &GetUserAllStaredReposQuery,
    ) -> Result<Vec<crate::models::Repos4User>> {
        let path = "/user/stared-repos".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            if let Some(ref v) = query.search {
                pairs.append_pair("search", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.flags_match {
                pairs.append_pair("flags_match", v);
            }
            if let Some(ref v) = query.status {
                pairs.append_pair("status", v);
            }
            if let Some(v) = query.desc {
                pairs.append_pair("desc", &v.to_string());
            }
            if let Some(ref v) = query.order_by {
                pairs.append_pair("order_by", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::Repos4User>>(Method::GET, url)
            .await
    }

    /// 获取指定用户的 star 仓库列表。Get the list of repositories starred by the specified user.
    ///
    /// `GET /users/{username}/stared-repos`
    pub async fn get_user_stared_repos(
        &self,
        username: String,
        query: &GetUserStaredReposQuery,
    ) -> Result<Vec<crate::models::Repos4User>> {
        let path = format!("/users/{}/stared-repos", username);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.search {
                pairs.append_pair("search", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.flags_match {
                pairs.append_pair("flags_match", v);
            }
            if let Some(ref v) = query.status {
                pairs.append_pair("status", v);
            }
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            if let Some(v) = query.desc {
                pairs.append_pair("desc", &v.to_string());
            }
            if let Some(ref v) = query.order_by {
                pairs.append_pair("order_by", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::Repos4User>>(Method::GET, url)
            .await
    }

    /// 获取指定仓库的star用户列表。Get the list of users who starred the specified repository.
    ///
    /// `GET /{slug}/-/stars`
    pub async fn list_star_users(
        &self,
        slug: String,
        query: &ListStarUsersQuery,
    ) -> Result<crate::models::RepoStarUsers> {
        let path = format!("/{}/-/stars", slug);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.filter_type {
                pairs.append_pair("filter_type", v);
            }
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::RepoStarUsers>(Method::GET, url)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetUserAllStaredReposQuery {
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
    /// Filter by repositories
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// 仓库类型标记,逗号分隔。Repository type flags, comma separated
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// flags 多值匹配模式。Flags match mode when multiple flags provided
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags_match: Option<String>,
    /// 仓库状态。Repository status
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    /// 排序顺序。Ordering.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub desc: Option<bool>,
    /// Order field
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub order_by: Option<String>,
}

impl GetUserAllStaredReposQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
    /// Set `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }
    /// Set `flags` query parameter.
    pub fn flags(mut self, v: impl Into<String>) -> Self {
        self.flags = Some(v.into());
        self
    }
    /// Set `flags_match` query parameter.
    pub fn flags_match(mut self, v: impl Into<String>) -> Self {
        self.flags_match = Some(v.into());
        self
    }
    /// Set `status` query parameter.
    pub fn status(mut self, v: impl Into<String>) -> Self {
        self.status = Some(v.into());
        self
    }
    /// Set `desc` query parameter.
    pub fn desc(mut self, v: impl Into<bool>) -> Self {
        self.desc = Some(v.into());
        self
    }
    /// Set `order_by` query parameter.
    pub fn order_by(mut self, v: impl Into<String>) -> Self {
        self.order_by = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetUserStaredReposQuery {
    /// 过滤仓库。Filter by repositories
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// 仓库类型标记,逗号分隔。Repository type flags, comma separated
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// flags 多值匹配模式。Flags match mode when multiple flags provided
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags_match: Option<String>,
    /// 仓库状态。Repository status
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
    /// Ordering
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub desc: Option<bool>,
    /// Order field
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub order_by: Option<String>,
}

impl GetUserStaredReposQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }
    /// Set `flags` query parameter.
    pub fn flags(mut self, v: impl Into<String>) -> Self {
        self.flags = Some(v.into());
        self
    }
    /// Set `flags_match` query parameter.
    pub fn flags_match(mut self, v: impl Into<String>) -> Self {
        self.flags_match = Some(v.into());
        self
    }
    /// Set `status` query parameter.
    pub fn status(mut self, v: impl Into<String>) -> Self {
        self.status = Some(v.into());
        self
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
    /// Set `desc` query parameter.
    pub fn desc(mut self, v: impl Into<bool>) -> Self {
        self.desc = Some(v.into());
        self
    }
    /// Set `order_by` query parameter.
    pub fn order_by(mut self, v: impl Into<String>) -> Self {
        self.order_by = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListStarUsersQuery {
    /// Filter type
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub filter_type: Option<String>,
    /// page
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// page
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
}

impl ListStarUsersQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `filter_type` query parameter.
    pub fn filter_type(mut self, v: impl Into<String>) -> Self {
        self.filter_type = Some(v.into());
        self
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
}