gitbundle_sdk/apis/
connectors_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.2.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 [`delete_connector`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum DeleteConnectorError {
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/// struct for typed errors of method [`get_connector`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetConnectorError {
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
45/// struct for typed errors of method [`patch_connector`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum PatchConnectorError {
49    Status400(models::JsonErrorResponseNull),
50    Status401(models::JsonErrorResponseNull),
51    Status403(models::JsonErrorResponseNull),
52    Status404(models::JsonErrorResponseNull),
53    Status409(models::JsonErrorResponseNull),
54    Status429(models::JsonErrorResponseNull),
55    Status500(models::JsonErrorResponseNull),
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`post_connector`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum PostConnectorError {
63    Status400(models::JsonErrorResponseNull),
64    Status401(models::JsonErrorResponseNull),
65    Status403(models::JsonErrorResponseNull),
66    Status404(models::JsonErrorResponseNull),
67    Status409(models::JsonErrorResponseNull),
68    Status429(models::JsonErrorResponseNull),
69    Status500(models::JsonErrorResponseNull),
70    UnknownValue(serde_json::Value),
71}
72
73pub async fn delete_connector(
74    configuration: &configuration::Configuration,
75    connector_ref: &str,
76) -> Result<(), Error<DeleteConnectorError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_path_connector_ref = connector_ref;
79
80    let uri_str = format!(
81        "{}/connectors/{connector_ref}",
82        configuration.base_path,
83        connector_ref = crate::apis::urlencode(p_path_connector_ref)
84    );
85    let mut req_builder = configuration
86        .client
87        .request(reqwest::Method::DELETE, &uri_str);
88
89    if let Some(ref apikey) = configuration.api_key {
90        let key = apikey.key.clone();
91        let value = match apikey.prefix {
92            Some(ref prefix) => format!("{} {}", prefix, key),
93            None => key,
94        };
95        req_builder = req_builder.query(&[("access_token", value)]);
96    }
97    if let Some(ref user_agent) = configuration.user_agent {
98        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99    }
100    if let Some(ref auth_conf) = configuration.basic_auth {
101        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
102    };
103    if let Some(ref token) = configuration.bearer_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111
112    if !status.is_client_error() && !status.is_server_error() {
113        Ok(())
114    } else {
115        let content = resp.text().await?;
116        let entity: Option<DeleteConnectorError> = serde_json::from_str(&content).ok();
117        Err(Error::ResponseError(ResponseContent {
118            status,
119            content,
120            entity,
121        }))
122    }
123}
124
125pub async fn get_connector(
126    configuration: &configuration::Configuration,
127    connector_ref: &str,
128) -> Result<models::ConnectorModel, Error<GetConnectorError>> {
129    // add a prefix to parameters to efficiently prevent name collisions
130    let p_path_connector_ref = connector_ref;
131
132    let uri_str = format!(
133        "{}/connectors/{connector_ref}",
134        configuration.base_path,
135        connector_ref = crate::apis::urlencode(p_path_connector_ref)
136    );
137    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
138
139    if let Some(ref apikey) = configuration.api_key {
140        let key = apikey.key.clone();
141        let value = match apikey.prefix {
142            Some(ref prefix) => format!("{} {}", prefix, key),
143            None => key,
144        };
145        req_builder = req_builder.query(&[("access_token", value)]);
146    }
147    if let Some(ref user_agent) = configuration.user_agent {
148        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149    }
150    if let Some(ref auth_conf) = configuration.basic_auth {
151        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
152    };
153    if let Some(ref token) = configuration.bearer_access_token {
154        req_builder = req_builder.bearer_auth(token.to_owned());
155    };
156
157    let req = req_builder.build()?;
158    let resp = configuration.client.execute(req).await?;
159
160    let status = resp.status();
161    let content_type = resp
162        .headers()
163        .get("content-type")
164        .and_then(|v| v.to_str().ok())
165        .unwrap_or("application/octet-stream");
166    let content_type = super::ContentType::from(content_type);
167
168    if !status.is_client_error() && !status.is_server_error() {
169        let content = resp.text().await?;
170        match content_type {
171            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
172            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectorModel`"))),
173            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConnectorModel`")))),
174        }
175    } else {
176        let content = resp.text().await?;
177        let entity: Option<GetConnectorError> = serde_json::from_str(&content).ok();
178        Err(Error::ResponseError(ResponseContent {
179            status,
180            content,
181            entity,
182        }))
183    }
184}
185
186pub async fn patch_connector(
187    configuration: &configuration::Configuration,
188    connector_ref: &str,
189    connector_patch_input: models::ConnectorPatchInput,
190) -> Result<models::ConnectorModel, Error<PatchConnectorError>> {
191    // add a prefix to parameters to efficiently prevent name collisions
192    let p_path_connector_ref = connector_ref;
193    let p_body_connector_patch_input = connector_patch_input;
194
195    let uri_str = format!(
196        "{}/connectors/{connector_ref}",
197        configuration.base_path,
198        connector_ref = crate::apis::urlencode(p_path_connector_ref)
199    );
200    let mut req_builder = configuration
201        .client
202        .request(reqwest::Method::PATCH, &uri_str);
203
204    if let Some(ref apikey) = configuration.api_key {
205        let key = apikey.key.clone();
206        let value = match apikey.prefix {
207            Some(ref prefix) => format!("{} {}", prefix, key),
208            None => key,
209        };
210        req_builder = req_builder.query(&[("access_token", value)]);
211    }
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(ref auth_conf) = configuration.basic_auth {
216        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
217    };
218    if let Some(ref token) = configuration.bearer_access_token {
219        req_builder = req_builder.bearer_auth(token.to_owned());
220    };
221    req_builder = req_builder.json(&p_body_connector_patch_input);
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227    let content_type = resp
228        .headers()
229        .get("content-type")
230        .and_then(|v| v.to_str().ok())
231        .unwrap_or("application/octet-stream");
232    let content_type = super::ContentType::from(content_type);
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        match content_type {
237            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectorModel`"))),
239            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConnectorModel`")))),
240        }
241    } else {
242        let content = resp.text().await?;
243        let entity: Option<PatchConnectorError> = serde_json::from_str(&content).ok();
244        Err(Error::ResponseError(ResponseContent {
245            status,
246            content,
247            entity,
248        }))
249    }
250}
251
252pub async fn post_connector(
253    configuration: &configuration::Configuration,
254    connector_create_input: models::ConnectorCreateInput,
255) -> Result<models::ConnectorModel, Error<PostConnectorError>> {
256    // add a prefix to parameters to efficiently prevent name collisions
257    let p_body_connector_create_input = connector_create_input;
258
259    let uri_str = format!("{}/connectors", configuration.base_path);
260    let mut req_builder = configuration
261        .client
262        .request(reqwest::Method::POST, &uri_str);
263
264    if let Some(ref apikey) = configuration.api_key {
265        let key = apikey.key.clone();
266        let value = match apikey.prefix {
267            Some(ref prefix) => format!("{} {}", prefix, key),
268            None => key,
269        };
270        req_builder = req_builder.query(&[("access_token", value)]);
271    }
272    if let Some(ref user_agent) = configuration.user_agent {
273        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274    }
275    if let Some(ref auth_conf) = configuration.basic_auth {
276        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
277    };
278    if let Some(ref token) = configuration.bearer_access_token {
279        req_builder = req_builder.bearer_auth(token.to_owned());
280    };
281    req_builder = req_builder.json(&p_body_connector_create_input);
282
283    let req = req_builder.build()?;
284    let resp = configuration.client.execute(req).await?;
285
286    let status = resp.status();
287    let content_type = resp
288        .headers()
289        .get("content-type")
290        .and_then(|v| v.to_str().ok())
291        .unwrap_or("application/octet-stream");
292    let content_type = super::ContentType::from(content_type);
293
294    if !status.is_client_error() && !status.is_server_error() {
295        let content = resp.text().await?;
296        match content_type {
297            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
298            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConnectorModel`"))),
299            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConnectorModel`")))),
300        }
301    } else {
302        let content = resp.text().await?;
303        let entity: Option<PostConnectorError> = serde_json::from_str(&content).ok();
304        Err(Error::ResponseError(ResponseContent {
305            status,
306            content,
307            entity,
308        }))
309    }
310}