gitbundle_sdk/apis/
resources_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum GetGitignoresError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetLicensesError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45pub async fn get_gitignores(
46 configuration: &configuration::Configuration,
47) -> Result<Vec<String>, Error<GetGitignoresError>> {
48 let uri_str = format!("{}/resources/gitignore", configuration.base_path);
49 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54
55 let req = req_builder.build()?;
56 let resp = configuration.client.execute(req).await?;
57
58 let status = resp.status();
59 let content_type = resp
60 .headers()
61 .get("content-type")
62 .and_then(|v| v.to_str().ok())
63 .unwrap_or("application/octet-stream");
64 let content_type = super::ContentType::from(content_type);
65
66 if !status.is_client_error() && !status.is_server_error() {
67 let content = resp.text().await?;
68 match content_type {
69 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<String>`"))),
71 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<String>`")))),
72 }
73 } else {
74 let content = resp.text().await?;
75 let entity: Option<GetGitignoresError> = serde_json::from_str(&content).ok();
76 Err(Error::ResponseError(ResponseContent {
77 status,
78 content,
79 entity,
80 }))
81 }
82}
83
84pub async fn get_licenses(
85 configuration: &configuration::Configuration,
86) -> Result<Vec<models::License>, Error<GetLicensesError>> {
87 let uri_str = format!("{}/resources/license", configuration.base_path);
88 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
89
90 if let Some(ref user_agent) = configuration.user_agent {
91 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92 }
93
94 let req = req_builder.build()?;
95 let resp = configuration.client.execute(req).await?;
96
97 let status = resp.status();
98 let content_type = resp
99 .headers()
100 .get("content-type")
101 .and_then(|v| v.to_str().ok())
102 .unwrap_or("application/octet-stream");
103 let content_type = super::ContentType::from(content_type);
104
105 if !status.is_client_error() && !status.is_server_error() {
106 let content = resp.text().await?;
107 match content_type {
108 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
109 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::License>`"))),
110 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::License>`")))),
111 }
112 } else {
113 let content = resp.text().await?;
114 let entity: Option<GetLicensesError> = serde_json::from_str(&content).ok();
115 Err(Error::ResponseError(ResponseContent {
116 status,
117 content,
118 entity,
119 }))
120 }
121}