firefly_iii/apis/
configuration_api.rs1#![allow(unused_imports)]
12
13use reqwest;
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models::{self, *};
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum GetConfigurationError {
23 Status401(models::UnauthenticatedResponse),
24 Status404(models::NotFoundResponse),
25 Status400(models::BadRequestResponse),
26 Status500(models::InternalExceptionResponse),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetSingleConfigurationError {
34 Status401(models::UnauthenticatedResponse),
35 Status404(models::NotFoundResponse),
36 Status400(models::BadRequestResponse),
37 Status500(models::InternalExceptionResponse),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum SetConfigurationError {
45 Status422(models::ValidationErrorResponse),
46 Status401(models::UnauthenticatedResponse),
47 Status404(models::NotFoundResponse),
48 Status400(models::BadRequestResponse),
49 Status500(models::InternalExceptionResponse),
50 UnknownValue(serde_json::Value),
51}
52
53pub async fn get_configuration(
55 configuration: &configuration::Configuration,
56 x_trace_id: Option<&str>,
57) -> Result<Vec<models::Configuration>, Error<GetConfigurationError>> {
58 let local_var_configuration = configuration;
59
60 let local_var_client = &local_var_configuration.client;
61
62 let local_var_uri_str = format!("{}/v1/configuration", local_var_configuration.base_path);
63 let mut local_var_req_builder =
64 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
65
66 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
67 local_var_req_builder =
68 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69 }
70 if let Some(local_var_param_value) = x_trace_id {
71 local_var_req_builder =
72 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
73 }
74 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
75 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
76 };
77 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
78 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
79 };
80
81 let local_var_req = local_var_req_builder.build()?;
82 let local_var_resp = local_var_client.execute(local_var_req).await?;
83
84 let local_var_status = local_var_resp.status();
85 let local_var_content = local_var_resp.text().await?;
86
87 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
88 serde_json::from_str(&local_var_content).map_err(Error::from)
89 } else {
90 let local_var_entity: Option<GetConfigurationError> =
91 serde_json::from_str(&local_var_content).ok();
92 let local_var_error = ResponseContent {
93 status: local_var_status,
94 content: local_var_content,
95 entity: local_var_entity,
96 };
97 Err(Error::ResponseError(local_var_error))
98 }
99}
100
101pub async fn get_single_configuration(
103 configuration: &configuration::Configuration,
104 name: ConfigValueFilter,
105 x_trace_id: Option<&str>,
106) -> Result<models::ConfigurationSingle, Error<GetSingleConfigurationError>> {
107 let local_var_configuration = configuration;
108
109 let local_var_client = &local_var_configuration.client;
110
111 let local_var_uri_str = format!(
112 "{}/v1/configuration/{name}",
113 local_var_configuration.base_path,
114 name = name
115 );
116 let mut local_var_req_builder =
117 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
118
119 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
120 local_var_req_builder =
121 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122 }
123 if let Some(local_var_param_value) = x_trace_id {
124 local_var_req_builder =
125 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
126 }
127 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
128 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
129 };
130 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
131 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
132 };
133
134 let local_var_req = local_var_req_builder.build()?;
135 let local_var_resp = local_var_client.execute(local_var_req).await?;
136
137 let local_var_status = local_var_resp.status();
138 let local_var_content = local_var_resp.text().await?;
139
140 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
141 serde_json::from_str(&local_var_content).map_err(Error::from)
142 } else {
143 let local_var_entity: Option<GetSingleConfigurationError> =
144 serde_json::from_str(&local_var_content).ok();
145 let local_var_error = ResponseContent {
146 status: local_var_status,
147 content: local_var_content,
148 entity: local_var_entity,
149 };
150 Err(Error::ResponseError(local_var_error))
151 }
152}
153
154pub async fn set_configuration(
156 configuration: &configuration::Configuration,
157 name: ConfigValueUpdateFilter,
158 value: models::PolymorphicProperty,
159 x_trace_id: Option<&str>,
160) -> Result<models::ConfigurationSingle, Error<SetConfigurationError>> {
161 let local_var_configuration = configuration;
162
163 let local_var_client = &local_var_configuration.client;
164
165 let local_var_uri_str = format!(
166 "{}/v1/configuration/{name}",
167 local_var_configuration.base_path,
168 name = name
169 );
170 let mut local_var_req_builder =
171 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
172
173 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
174 local_var_req_builder =
175 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176 }
177 if let Some(local_var_param_value) = x_trace_id {
178 local_var_req_builder =
179 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
180 }
181 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
182 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
183 };
184 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
185 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
186 };
187 let mut local_var_form_params = std::collections::HashMap::new();
188 local_var_form_params.insert("value", value.to_string());
189 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
190
191 let local_var_req = local_var_req_builder.build()?;
192 let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194 let local_var_status = local_var_resp.status();
195 let local_var_content = local_var_resp.text().await?;
196
197 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198 serde_json::from_str(&local_var_content).map_err(Error::from)
199 } else {
200 let local_var_entity: Option<SetConfigurationError> =
201 serde_json::from_str(&local_var_content).ok();
202 let local_var_error = ResponseContent {
203 status: local_var_status,
204 content: local_var_content,
205 entity: local_var_entity,
206 };
207 Err(Error::ResponseError(local_var_error))
208 }
209}