openapi_github/apis/
licenses_api.rs

1/*
2 * GitHub's official OpenAPI spec + Octokit extension
3 *
4 * OpenAPI specs from https://github.com/github/rest-api-description with the 'x-octokit' extension required by the Octokit SDKs
5 *
6 * The version of the OpenAPI document: 16.6.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`licenses_slash_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum LicensesSlashGetError {
22    Status403(models::BasicError),
23    Status404(models::BasicError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`licenses_slash_get_all_commonly_used`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum LicensesSlashGetAllCommonlyUsedError {
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`licenses_slash_get_for_repo`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum LicensesSlashGetForRepoError {
38    Status404(models::BasicError),
39    UnknownValue(serde_json::Value),
40}
41
42
43/// Gets information about a specific license. For more information, see \"[Licensing a repository ](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository).\"
44pub async fn licenses_slash_get(configuration: &configuration::Configuration, license: &str) -> Result<models::License, Error<LicensesSlashGetError>> {
45    let local_var_configuration = configuration;
46
47    let local_var_client = &local_var_configuration.client;
48
49    let local_var_uri_str = format!("{}/licenses/{license}", local_var_configuration.base_path, license=crate::apis::urlencode(license));
50    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
51
52    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
53        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
54    }
55
56    let local_var_req = local_var_req_builder.build()?;
57    let local_var_resp = local_var_client.execute(local_var_req).await?;
58
59    let local_var_status = local_var_resp.status();
60    let local_var_content = local_var_resp.text().await?;
61
62    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
63        serde_json::from_str(&local_var_content).map_err(Error::from)
64    } else {
65        let local_var_entity: Option<LicensesSlashGetError> = serde_json::from_str(&local_var_content).ok();
66        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
67        Err(Error::ResponseError(local_var_error))
68    }
69}
70
71/// Lists the most commonly used licenses on GitHub. For more information, see \"[Licensing a repository ](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository).\"
72pub async fn licenses_slash_get_all_commonly_used(configuration: &configuration::Configuration, featured: Option<bool>, per_page: Option<i32>, page: Option<i32>) -> Result<Vec<models::LicenseSimple>, Error<LicensesSlashGetAllCommonlyUsedError>> {
73    let local_var_configuration = configuration;
74
75    let local_var_client = &local_var_configuration.client;
76
77    let local_var_uri_str = format!("{}/licenses", local_var_configuration.base_path);
78    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_str) = featured {
81        local_var_req_builder = local_var_req_builder.query(&[("featured", &local_var_str.to_string())]);
82    }
83    if let Some(ref local_var_str) = per_page {
84        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
85    }
86    if let Some(ref local_var_str) = page {
87        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
88    }
89    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
90        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
91    }
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<LicensesSlashGetAllCommonlyUsedError> = serde_json::from_str(&local_var_content).ok();
103        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
104        Err(Error::ResponseError(local_var_error))
105    }
106}
107
108/// This method returns the contents of the repository's license file, if one is detected.  This endpoint supports the following custom media types. For more information, see \"[Media types](https://docs.github.com/rest/using-the-rest-api/getting-started-with-the-rest-api#media-types).\"  - **`application/vnd.github.raw+json`**: Returns the raw contents of the license. - **`application/vnd.github.html+json`**: Returns the license contents in HTML. Markup languages are rendered to HTML using GitHub's open-source [Markup library](https://github.com/github/markup).
109pub async fn licenses_slash_get_for_repo(configuration: &configuration::Configuration, owner: &str, repo: &str, r#ref: Option<&str>) -> Result<models::LicenseContent, Error<LicensesSlashGetForRepoError>> {
110    let local_var_configuration = configuration;
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/license", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo));
115    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
116
117    if let Some(ref local_var_str) = r#ref {
118        local_var_req_builder = local_var_req_builder.query(&[("ref", &local_var_str.to_string())]);
119    }
120    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
121        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122    }
123
124    let local_var_req = local_var_req_builder.build()?;
125    let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127    let local_var_status = local_var_resp.status();
128    let local_var_content = local_var_resp.text().await?;
129
130    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131        serde_json::from_str(&local_var_content).map_err(Error::from)
132    } else {
133        let local_var_entity: Option<LicensesSlashGetForRepoError> = serde_json::from_str(&local_var_content).ok();
134        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135        Err(Error::ResponseError(local_var_error))
136    }
137}
138