artcoded_api/apis/
pdf_controller_api.rs

1/*
2 * Artcoded
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`rotate`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum RotateError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`split_pdf`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum SplitPdfError {
27    UnknownValue(serde_json::Value),
28}
29
30pub async fn rotate(
31    configuration: &configuration::Configuration,
32    id: &str,
33    rotation: Option<i32>,
34) -> Result<(), Error<RotateError>> {
35    // add a prefix to parameters to efficiently prevent name collisions
36    let p_query_id = id;
37    let p_query_rotation = rotation;
38
39    let uri_str = format!("{}/api/pdf/rotate", configuration.base_path);
40    let mut req_builder = configuration
41        .client
42        .request(reqwest::Method::POST, &uri_str);
43
44    if let Some(ref param_value) = p_query_rotation {
45        req_builder = req_builder.query(&[("rotation", &param_value.to_string())]);
46    }
47    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref token) = configuration.bearer_access_token {
52        req_builder = req_builder.bearer_auth(token.to_owned());
53    };
54
55    let req = req_builder.build()?;
56    let resp = configuration.client.execute(req).await?;
57
58    let status = resp.status();
59
60    if !status.is_client_error() && !status.is_server_error() {
61        Ok(())
62    } else {
63        let content = resp.text().await?;
64        let entity: Option<RotateError> = serde_json::from_str(&content).ok();
65        Err(Error::ResponseError(ResponseContent {
66            status,
67            content,
68            entity,
69        }))
70    }
71}
72
73pub async fn split_pdf(
74    configuration: &configuration::Configuration,
75    pdf: std::path::PathBuf,
76) -> Result<reqwest::Response, Error<SplitPdfError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_form_pdf = pdf;
79
80    let uri_str = format!("{}/api/pdf/split", configuration.base_path);
81    let mut req_builder = configuration
82        .client
83        .request(reqwest::Method::POST, &uri_str);
84
85    if let Some(ref user_agent) = configuration.user_agent {
86        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87    }
88    if let Some(ref token) = configuration.bearer_access_token {
89        req_builder = req_builder.bearer_auth(token.to_owned());
90    };
91    let multipart_form = reqwest::multipart::Form::new();
92    // TODO: support file upload for 'pdf' parameter
93    req_builder = req_builder.multipart(multipart_form);
94
95    let req = req_builder.build()?;
96    let resp = configuration.client.execute(req).await?;
97
98    let status = resp.status();
99
100    if !status.is_client_error() && !status.is_server_error() {
101        Ok(resp)
102    } else {
103        let content = resp.text().await?;
104        let entity: Option<SplitPdfError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent {
106            status,
107            content,
108            entity,
109        }))
110    }
111}