rust_cnb/
repo_contributor.rs1use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8pub struct RepoContributorClient {
10 base_url: String,
11 client: Client,
12}
13
14impl RepoContributorClient {
15 pub fn new(base_url: String, client: Client) -> Self {
17 Self { base_url, client }
18 }
19
20 pub fn with_auth(self, token: &str) -> Self {
22 self
24 }
25
26 pub async fn get_repo_contributor_trend(
28 &self,
29 repo: String,
30 limit: Option<i64>,
31 exclude_external_users: Option<bool>,
32 ) -> Result<Value> {
33 let path = format!("/{}/-/contributor/trend", repo);
34 let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
35
36 if let Some(value) = limit {
37 url.query_pairs_mut().append_pair("limit", &value.to_string());
38 }
39 if let Some(value) = exclude_external_users {
40 url.query_pairs_mut().append_pair("exclude_external_users", &value.to_string());
41 }
42
43 let request = self.client.request(
44 reqwest::Method::GET,
45 url
46 );
47
48
49
50
51 let response = request.send().await?;
52
53 if response.status().is_success() {
54 let json: Value = response.json().await?;
55 Ok(json)
56 } else {
57 Err(ApiError::HttpError(response.status().as_u16()))
58 }
59 }
60
61}