gitbundle_sdk/apis/
bootstrap_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`get_bootstrap`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum GetBootstrapError {
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
31pub async fn get_bootstrap(
32    configuration: &configuration::Configuration,
33    bootstrap_ref: &str,
34    path: Option<&str>,
35) -> Result<models::BootstrapMetadata, Error<GetBootstrapError>> {
36    // add a prefix to parameters to efficiently prevent name collisions
37    let p_path_bootstrap_ref = bootstrap_ref;
38    let p_path_path = path;
39
40    let uri_str = format!(
41        "{}/bootstrap/{bootstrap_ref}/+/{path}",
42        configuration.base_path,
43        bootstrap_ref = crate::apis::urlencode(p_path_bootstrap_ref),
44        path = crate::apis::urlencode(p_path_path.unwrap())
45    );
46    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48    if let Some(ref apikey) = configuration.api_key {
49        let key = apikey.key.clone();
50        let value = match apikey.prefix {
51            Some(ref prefix) => format!("{} {}", prefix, key),
52            None => key,
53        };
54        req_builder = req_builder.query(&[("access_token", value)]);
55    }
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref auth_conf) = configuration.basic_auth {
60        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
61    };
62    if let Some(ref token) = configuration.bearer_access_token {
63        req_builder = req_builder.bearer_auth(token.to_owned());
64    };
65
66    let req = req_builder.build()?;
67    let resp = configuration.client.execute(req).await?;
68
69    let status = resp.status();
70    let content_type = resp
71        .headers()
72        .get("content-type")
73        .and_then(|v| v.to_str().ok())
74        .unwrap_or("application/octet-stream");
75    let content_type = super::ContentType::from(content_type);
76
77    if !status.is_client_error() && !status.is_server_error() {
78        let content = resp.text().await?;
79        match content_type {
80            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BootstrapMetadata`"))),
82            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BootstrapMetadata`")))),
83        }
84    } else {
85        let content = resp.text().await?;
86        let entity: Option<GetBootstrapError> = serde_json::from_str(&content).ok();
87        Err(Error::ResponseError(ResponseContent {
88            status,
89            content,
90            entity,
91        }))
92    }
93}