Skip to main content

firefly_iii/apis/
preferences_api.rs

1/*
2 * Firefly III API v6.4.14
3 *
4 * This is the documentation of the Firefly III API. Please report any bugs or issues. You may use the \"Authorize\" button to try the API below. <br><br> Please keep in mind that the demo site does **not** accept requests from `curl`, `colly`, `wget`, etc. You must use a browser or a tool like Insomnia to make your test requests. <br><br> To learn more about the idiosyncrasies of this API, please read about the API in the [Firefly III API documentation](https://docs.firefly-iii.org/references/firefly-iii/api/). <br><br> <small>This file was last generated on 2025-12-26 @ 15:17:41 (Europe/Amsterdam)</small>
5 *
6 * The version of the OpenAPI document: v6.4.14
7 * Contact: james@firefly-iii.org
8 * Generated by: https://openapi-generator.tech
9 */
10
11#![allow(unused_imports)]
12
13use reqwest;
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models::{self, *};
18
19/// struct for typed errors of method [`get_preference`]
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum GetPreferenceError {
23    Status401(models::UnauthenticatedResponse),
24    Status404(models::NotFoundResponse),
25    Status400(models::BadRequestResponse),
26    Status500(models::InternalExceptionResponse),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`list_preference`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ListPreferenceError {
34    Status401(models::UnauthenticatedResponse),
35    Status404(models::NotFoundResponse),
36    Status400(models::BadRequestResponse),
37    Status500(models::InternalExceptionResponse),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`store_preference`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum StorePreferenceError {
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
53/// struct for typed errors of method [`update_preference`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UpdatePreferenceError {
57    Status422(models::ValidationErrorResponse),
58    Status401(models::UnauthenticatedResponse),
59    Status404(models::NotFoundResponse),
60    Status400(models::BadRequestResponse),
61    Status500(models::InternalExceptionResponse),
62    UnknownValue(serde_json::Value),
63}
64
65/// Return a single preference and the value.
66pub async fn get_preference(
67    configuration: &configuration::Configuration,
68    name: &str,
69    x_trace_id: Option<&str>,
70) -> Result<models::PreferenceSingle, Error<GetPreferenceError>> {
71    let local_var_configuration = configuration;
72
73    let local_var_client = &local_var_configuration.client;
74
75    let local_var_uri_str = format!(
76        "{}/v1/preferences/{name}",
77        local_var_configuration.base_path,
78        name = crate::apis::urlencode(name)
79    );
80    let mut local_var_req_builder =
81        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
82
83    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
84        local_var_req_builder =
85            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87    if let Some(local_var_param_value) = x_trace_id {
88        local_var_req_builder =
89            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
90    }
91    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
92        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
93    };
94    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
95        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
96    };
97
98    let local_var_req = local_var_req_builder.build()?;
99    let local_var_resp = local_var_client.execute(local_var_req).await?;
100
101    let local_var_status = local_var_resp.status();
102    let local_var_content = local_var_resp.text().await?;
103
104    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
105        serde_json::from_str(&local_var_content).map_err(Error::from)
106    } else {
107        let local_var_entity: Option<GetPreferenceError> =
108            serde_json::from_str(&local_var_content).ok();
109        let local_var_error = ResponseContent {
110            status: local_var_status,
111            content: local_var_content,
112            entity: local_var_entity,
113        };
114        Err(Error::ResponseError(local_var_error))
115    }
116}
117
118/// List all of the preferences of the user.
119pub async fn list_preference(
120    configuration: &configuration::Configuration,
121    x_trace_id: Option<&str>,
122    limit: Option<i32>,
123    page: Option<i32>,
124) -> Result<models::PreferenceArray, Error<ListPreferenceError>> {
125    let local_var_configuration = configuration;
126
127    let local_var_client = &local_var_configuration.client;
128
129    let local_var_uri_str = format!("{}/v1/preferences", local_var_configuration.base_path);
130    let mut local_var_req_builder =
131        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_str) = limit {
134        local_var_req_builder =
135            local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
136    }
137    if let Some(ref local_var_str) = page {
138        local_var_req_builder =
139            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
140    }
141    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142        local_var_req_builder =
143            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
144    }
145    if let Some(local_var_param_value) = x_trace_id {
146        local_var_req_builder =
147            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
148    }
149    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
150        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
151    };
152    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
153        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
154    };
155
156    let local_var_req = local_var_req_builder.build()?;
157    let local_var_resp = local_var_client.execute(local_var_req).await?;
158
159    let local_var_status = local_var_resp.status();
160    let local_var_content = local_var_resp.text().await?;
161
162    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163        serde_json::from_str(&local_var_content).map_err(Error::from)
164    } else {
165        let local_var_entity: Option<ListPreferenceError> =
166            serde_json::from_str(&local_var_content).ok();
167        let local_var_error = ResponseContent {
168            status: local_var_status,
169            content: local_var_content,
170            entity: local_var_entity,
171        };
172        Err(Error::ResponseError(local_var_error))
173    }
174}
175
176/// This endpoint creates a new preference. The name and data are free-format, and entirely up to you. If the preference is not used in Firefly III itself it may not be configurable through the user interface, but you can use this endpoint to persist custom data for your own app.
177pub async fn store_preference(
178    configuration: &configuration::Configuration,
179    preference: Preference,
180    x_trace_id: Option<&str>,
181) -> Result<models::PreferenceSingle, Error<StorePreferenceError>> {
182    let local_var_configuration = configuration;
183
184    let local_var_client = &local_var_configuration.client;
185
186    let local_var_uri_str = format!("{}/v1/preferences", local_var_configuration.base_path);
187    let mut local_var_req_builder =
188        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
189
190    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
191        local_var_req_builder =
192            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
193    }
194    if let Some(local_var_param_value) = x_trace_id {
195        local_var_req_builder =
196            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
197    }
198    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
199        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
200    };
201    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
202        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
203    };
204    local_var_req_builder = local_var_req_builder.json(&preference);
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text().await?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<StorePreferenceError> =
216            serde_json::from_str(&local_var_content).ok();
217        let local_var_error = ResponseContent {
218            status: local_var_status,
219            content: local_var_content,
220            entity: local_var_entity,
221        };
222        Err(Error::ResponseError(local_var_error))
223    }
224}
225
226/// Update a user's preference.
227pub async fn update_preference(
228    configuration: &configuration::Configuration,
229    name: &str,
230    preference_update: PreferenceUpdate,
231    x_trace_id: Option<&str>,
232) -> Result<models::PreferenceSingle, Error<UpdatePreferenceError>> {
233    let local_var_configuration = configuration;
234
235    let local_var_client = &local_var_configuration.client;
236
237    let local_var_uri_str = format!(
238        "{}/v1/preferences/{name}",
239        local_var_configuration.base_path,
240        name = crate::apis::urlencode(name)
241    );
242    let mut local_var_req_builder =
243        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
244
245    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
246        local_var_req_builder =
247            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
248    }
249    if let Some(local_var_param_value) = x_trace_id {
250        local_var_req_builder =
251            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
252    }
253    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
254        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
255    };
256    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
257        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
258    };
259    local_var_req_builder = local_var_req_builder.json(&preference_update);
260
261    let local_var_req = local_var_req_builder.build()?;
262    let local_var_resp = local_var_client.execute(local_var_req).await?;
263
264    let local_var_status = local_var_resp.status();
265    let local_var_content = local_var_resp.text().await?;
266
267    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
268        serde_json::from_str(&local_var_content).map_err(Error::from)
269    } else {
270        let local_var_entity: Option<UpdatePreferenceError> =
271            serde_json::from_str(&local_var_content).ok();
272        let local_var_error = ResponseContent {
273            status: local_var_status,
274            content: local_var_content,
275            entity: local_var_entity,
276        };
277        Err(Error::ResponseError(local_var_error))
278    }
279}