Skip to main content

gitbundle_sdk/apis/
rules_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.4.1
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_rule`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum DeleteRuleError {
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_rule`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetRuleError {
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 [`get_rules`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetRulesError {
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 [`patch_rule`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum PatchRuleError {
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
73/// struct for typed errors of method [`post_rule`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum PostRuleError {
77    Status400(models::JsonErrorResponseNull),
78    Status401(models::JsonErrorResponseNull),
79    Status403(models::JsonErrorResponseNull),
80    Status404(models::JsonErrorResponseNull),
81    Status409(models::JsonErrorResponseNull),
82    Status429(models::JsonErrorResponseNull),
83    Status500(models::JsonErrorResponseNull),
84    UnknownValue(serde_json::Value),
85}
86
87pub async fn delete_rule(
88    configuration: &configuration::Configuration,
89    repo_ref: &str,
90    rule_identifier: &str,
91) -> Result<(), Error<DeleteRuleError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_path_repo_ref = repo_ref;
94    let p_path_rule_identifier = rule_identifier;
95
96    let uri_str = format!(
97        "{}/repos/{repo_ref}/+/rules/{rule_identifier}",
98        configuration.base_path,
99        repo_ref = crate::apis::urlencode(p_path_repo_ref),
100        rule_identifier = crate::apis::urlencode(p_path_rule_identifier)
101    );
102    let mut req_builder = configuration
103        .client
104        .request(reqwest::Method::DELETE, &uri_str);
105
106    if let Some(ref apikey) = configuration.api_key {
107        let key = apikey.key.clone();
108        let value = match apikey.prefix {
109            Some(ref prefix) => format!("{} {}", prefix, key),
110            None => key,
111        };
112        req_builder = req_builder.query(&[("access_token", value)]);
113    }
114    if let Some(ref user_agent) = configuration.user_agent {
115        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116    }
117    if let Some(ref auth_conf) = configuration.basic_auth {
118        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
119    };
120    if let Some(ref token) = configuration.bearer_access_token {
121        req_builder = req_builder.bearer_auth(token.to_owned());
122    };
123
124    let req = req_builder.build()?;
125    let resp = configuration.client.execute(req).await?;
126
127    let status = resp.status();
128
129    if !status.is_client_error() && !status.is_server_error() {
130        Ok(())
131    } else {
132        let content = resp.text().await?;
133        let entity: Option<DeleteRuleError> = serde_json::from_str(&content).ok();
134        Err(Error::ResponseError(ResponseContent {
135            status,
136            content,
137            entity,
138        }))
139    }
140}
141
142pub async fn get_rule(
143    configuration: &configuration::Configuration,
144    repo_ref: &str,
145    rule_identifier: &str,
146) -> Result<models::RuleModel, Error<GetRuleError>> {
147    // add a prefix to parameters to efficiently prevent name collisions
148    let p_path_repo_ref = repo_ref;
149    let p_path_rule_identifier = rule_identifier;
150
151    let uri_str = format!(
152        "{}/repos/{repo_ref}/+/rules/{rule_identifier}",
153        configuration.base_path,
154        repo_ref = crate::apis::urlencode(p_path_repo_ref),
155        rule_identifier = crate::apis::urlencode(p_path_rule_identifier)
156    );
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref apikey) = configuration.api_key {
160        let key = apikey.key.clone();
161        let value = match apikey.prefix {
162            Some(ref prefix) => format!("{} {}", prefix, key),
163            None => key,
164        };
165        req_builder = req_builder.query(&[("access_token", value)]);
166    }
167    if let Some(ref user_agent) = configuration.user_agent {
168        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
169    }
170    if let Some(ref auth_conf) = configuration.basic_auth {
171        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
172    };
173    if let Some(ref token) = configuration.bearer_access_token {
174        req_builder = req_builder.bearer_auth(token.to_owned());
175    };
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RuleModel`"))),
193            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RuleModel`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<GetRuleError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent {
199            status,
200            content,
201            entity,
202        }))
203    }
204}
205
206pub async fn get_rules(
207    configuration: &configuration::Configuration,
208    repo_ref: &str,
209    page: Option<i64>,
210    size: Option<i64>,
211    query: Option<&str>,
212    states: Option<Vec<models::RuleState>>,
213    sort: Option<models::RuleSort>,
214    order: Option<models::OrderOption>,
215) -> Result<Vec<models::RuleModel>, Error<GetRulesError>> {
216    // add a prefix to parameters to efficiently prevent name collisions
217    let p_path_repo_ref = repo_ref;
218    let p_query_page = page;
219    let p_query_size = size;
220    let p_query_query = query;
221    let p_query_states = states;
222    let p_query_sort = sort;
223    let p_query_order = order;
224
225    let uri_str = format!(
226        "{}/repos/{repo_ref}/+/rules",
227        configuration.base_path,
228        repo_ref = crate::apis::urlencode(p_path_repo_ref)
229    );
230    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232    if let Some(ref param_value) = p_query_page {
233        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
234    }
235    if let Some(ref param_value) = p_query_size {
236        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
237    }
238    if let Some(ref param_value) = p_query_query {
239        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
240    }
241    if let Some(ref param_value) = p_query_states {
242        req_builder = match "multi" {
243            "multi" => req_builder.query(
244                &param_value
245                    .iter()
246                    .map(|p| ("states".to_owned(), p.to_string()))
247                    .collect::<Vec<(std::string::String, std::string::String)>>(),
248            ),
249            _ => req_builder.query(&[(
250                "states",
251                &param_value
252                    .iter()
253                    .map(|p| p.to_string())
254                    .collect::<Vec<String>>()
255                    .join(",")
256                    .to_string(),
257            )]),
258        };
259    }
260    if let Some(ref param_value) = p_query_sort {
261        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
262    }
263    if let Some(ref param_value) = p_query_order {
264        req_builder = req_builder.query(&[("order", &param_value.to_string())]);
265    }
266    if let Some(ref apikey) = configuration.api_key {
267        let key = apikey.key.clone();
268        let value = match apikey.prefix {
269            Some(ref prefix) => format!("{} {}", prefix, key),
270            None => key,
271        };
272        req_builder = req_builder.query(&[("access_token", value)]);
273    }
274    if let Some(ref user_agent) = configuration.user_agent {
275        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
276    }
277    if let Some(ref auth_conf) = configuration.basic_auth {
278        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
279    };
280    if let Some(ref token) = configuration.bearer_access_token {
281        req_builder = req_builder.bearer_auth(token.to_owned());
282    };
283
284    let req = req_builder.build()?;
285    let resp = configuration.client.execute(req).await?;
286
287    let status = resp.status();
288    let content_type = resp
289        .headers()
290        .get("content-type")
291        .and_then(|v| v.to_str().ok())
292        .unwrap_or("application/octet-stream");
293    let content_type = super::ContentType::from(content_type);
294
295    if !status.is_client_error() && !status.is_server_error() {
296        let content = resp.text().await?;
297        match content_type {
298            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
299            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::RuleModel&gt;`"))),
300            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::RuleModel&gt;`")))),
301        }
302    } else {
303        let content = resp.text().await?;
304        let entity: Option<GetRulesError> = serde_json::from_str(&content).ok();
305        Err(Error::ResponseError(ResponseContent {
306            status,
307            content,
308            entity,
309        }))
310    }
311}
312
313pub async fn patch_rule(
314    configuration: &configuration::Configuration,
315    repo_ref: &str,
316    rule_identifier: &str,
317    rule_patch_input: models::RulePatchInput,
318) -> Result<models::RuleModel, Error<PatchRuleError>> {
319    // add a prefix to parameters to efficiently prevent name collisions
320    let p_path_repo_ref = repo_ref;
321    let p_path_rule_identifier = rule_identifier;
322    let p_body_rule_patch_input = rule_patch_input;
323
324    let uri_str = format!(
325        "{}/repos/{repo_ref}/+/rules/{rule_identifier}",
326        configuration.base_path,
327        repo_ref = crate::apis::urlencode(p_path_repo_ref),
328        rule_identifier = crate::apis::urlencode(p_path_rule_identifier)
329    );
330    let mut req_builder = configuration
331        .client
332        .request(reqwest::Method::PATCH, &uri_str);
333
334    if let Some(ref apikey) = configuration.api_key {
335        let key = apikey.key.clone();
336        let value = match apikey.prefix {
337            Some(ref prefix) => format!("{} {}", prefix, key),
338            None => key,
339        };
340        req_builder = req_builder.query(&[("access_token", value)]);
341    }
342    if let Some(ref user_agent) = configuration.user_agent {
343        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
344    }
345    if let Some(ref auth_conf) = configuration.basic_auth {
346        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
347    };
348    if let Some(ref token) = configuration.bearer_access_token {
349        req_builder = req_builder.bearer_auth(token.to_owned());
350    };
351    req_builder = req_builder.json(&p_body_rule_patch_input);
352
353    let req = req_builder.build()?;
354    let resp = configuration.client.execute(req).await?;
355
356    let status = resp.status();
357    let content_type = resp
358        .headers()
359        .get("content-type")
360        .and_then(|v| v.to_str().ok())
361        .unwrap_or("application/octet-stream");
362    let content_type = super::ContentType::from(content_type);
363
364    if !status.is_client_error() && !status.is_server_error() {
365        let content = resp.text().await?;
366        match content_type {
367            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
368            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RuleModel`"))),
369            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RuleModel`")))),
370        }
371    } else {
372        let content = resp.text().await?;
373        let entity: Option<PatchRuleError> = serde_json::from_str(&content).ok();
374        Err(Error::ResponseError(ResponseContent {
375            status,
376            content,
377            entity,
378        }))
379    }
380}
381
382pub async fn post_rule(
383    configuration: &configuration::Configuration,
384    repo_ref: &str,
385    rule_create_input: models::RuleCreateInput,
386) -> Result<models::RuleModel, Error<PostRuleError>> {
387    // add a prefix to parameters to efficiently prevent name collisions
388    let p_path_repo_ref = repo_ref;
389    let p_body_rule_create_input = rule_create_input;
390
391    let uri_str = format!(
392        "{}/repos/{repo_ref}/+/rules",
393        configuration.base_path,
394        repo_ref = crate::apis::urlencode(p_path_repo_ref)
395    );
396    let mut req_builder = configuration
397        .client
398        .request(reqwest::Method::POST, &uri_str);
399
400    if let Some(ref apikey) = configuration.api_key {
401        let key = apikey.key.clone();
402        let value = match apikey.prefix {
403            Some(ref prefix) => format!("{} {}", prefix, key),
404            None => key,
405        };
406        req_builder = req_builder.query(&[("access_token", value)]);
407    }
408    if let Some(ref user_agent) = configuration.user_agent {
409        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
410    }
411    if let Some(ref auth_conf) = configuration.basic_auth {
412        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
413    };
414    if let Some(ref token) = configuration.bearer_access_token {
415        req_builder = req_builder.bearer_auth(token.to_owned());
416    };
417    req_builder = req_builder.json(&p_body_rule_create_input);
418
419    let req = req_builder.build()?;
420    let resp = configuration.client.execute(req).await?;
421
422    let status = resp.status();
423    let content_type = resp
424        .headers()
425        .get("content-type")
426        .and_then(|v| v.to_str().ok())
427        .unwrap_or("application/octet-stream");
428    let content_type = super::ContentType::from(content_type);
429
430    if !status.is_client_error() && !status.is_server_error() {
431        let content = resp.text().await?;
432        match content_type {
433            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
434            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RuleModel`"))),
435            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RuleModel`")))),
436        }
437    } else {
438        let content = resp.text().await?;
439        let entity: Option<PostRuleError> = serde_json::from_str(&content).ok();
440        Err(Error::ResponseError(ResponseContent {
441            status,
442            content,
443            entity,
444        }))
445    }
446}