clientapi_pbs/apis/
pull_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PullCreatePullError {
22 Status400(models::PbsError),
23 Status401(models::PbsError),
24 Status403(models::PbsError),
25 Status404(models::PbsError),
26 Status500(models::PbsError),
27 Status501(models::PbsError),
28 Status503(models::PbsError),
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn pull_create_pull(configuration: &configuration::Configuration, pull_create_pull_request: models::PullCreatePullRequest) -> Result<models::PullCreatePullResponse, Error<PullCreatePullError>> {
35 let p_body_pull_create_pull_request = pull_create_pull_request;
37
38 let uri_str = format!("{}/pull", configuration.base_path);
39 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
40
41 if let Some(ref user_agent) = configuration.user_agent {
42 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43 }
44 if let Some(ref apikey) = configuration.api_key {
45 let key = apikey.key.clone();
46 let value = match apikey.prefix {
47 Some(ref prefix) => format!("{} {}", prefix, key),
48 None => key,
49 };
50 req_builder = req_builder.header("Authorization", value);
51 };
52 if let Some(ref apikey) = configuration.api_key {
53 let key = apikey.key.clone();
54 let value = match apikey.prefix {
55 Some(ref prefix) => format!("{} {}", prefix, key),
56 None => key,
57 };
58 req_builder = req_builder.header("CSRFPreventionToken", value);
59 };
60 req_builder = req_builder.json(&p_body_pull_create_pull_request);
61
62 let req = req_builder.build()?;
63 let resp = configuration.client.execute(req).await?;
64
65 let status = resp.status();
66 let content_type = resp
67 .headers()
68 .get("content-type")
69 .and_then(|v| v.to_str().ok())
70 .unwrap_or("application/octet-stream");
71 let content_type = super::ContentType::from(content_type);
72
73 if !status.is_client_error() && !status.is_server_error() {
74 let content = resp.text().await?;
75 match content_type {
76 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
77 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PullCreatePullResponse`"))),
78 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PullCreatePullResponse`")))),
79 }
80 } else {
81 let content = resp.text().await?;
82 let entity: Option<PullCreatePullError> = serde_json::from_str(&content).ok();
83 Err(Error::ResponseError(ResponseContent { status, content, entity }))
84 }
85}
86