firefly-iii 0.3.0

Rust API client for firefly-iii
Documentation
/*
 * Firefly III API v6.4.14
 *
 * 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>
 *
 * The version of the OpenAPI document: v6.4.14
 * Contact: james@firefly-iii.org
 * Generated by: https://openapi-generator.tech
 */

#![allow(unused_imports)]

use reqwest;

use super::{configuration, Error};
use crate::apis::ResponseContent;
use crate::models::{self, *};

/// struct for typed errors of method [`get_chart_account_overview`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetChartAccountOverviewError {
    Status401(models::UnauthenticatedResponse),
    Status404(models::NotFoundResponse),
    Status400(models::BadRequestResponse),
    Status422(models::ValidationErrorResponse),
    Status500(models::InternalExceptionResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_chart_balance`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetChartBalanceError {
    Status401(models::UnauthenticatedResponse),
    Status404(models::NotFoundResponse),
    Status400(models::BadRequestResponse),
    Status422(models::ValidationErrorResponse),
    Status500(models::InternalExceptionResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_chart_budget_overview`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetChartBudgetOverviewError {
    Status401(models::UnauthenticatedResponse),
    Status404(models::NotFoundResponse),
    Status400(models::BadRequestResponse),
    Status422(models::ValidationErrorResponse),
    Status500(models::InternalExceptionResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_chart_category_overview`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetChartCategoryOverviewError {
    Status401(models::UnauthenticatedResponse),
    Status404(models::NotFoundResponse),
    Status400(models::BadRequestResponse),
    Status422(models::ValidationErrorResponse),
    Status500(models::InternalExceptionResponse),
    UnknownValue(serde_json::Value),
}

/// This endpoint returns the data required to generate a chart with basic asset account balance information. This is used on the dashboard.
pub async fn get_chart_account_overview(
    configuration: &configuration::Configuration,
    start: String,
    end: String,
    x_trace_id: Option<&str>,
    period: Option<&str>,
    preselected: Option<&str>,
) -> Result<Vec<models::ChartDataSet>, Error<GetChartAccountOverviewError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/v1/chart/account/overview",
        local_var_configuration.base_path
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
    if let Some(ref local_var_str) = period {
        local_var_req_builder =
            local_var_req_builder.query(&[("period", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = preselected {
        local_var_req_builder =
            local_var_req_builder.query(&[("preselected", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = x_trace_id {
        local_var_req_builder =
            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetChartAccountOverviewError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}

/// This endpoint returns the data required to generate a chart with balance information.
pub async fn get_chart_balance(
    configuration: &configuration::Configuration,
    start: String,
    end: String,
    x_trace_id: Option<&str>,
    period: Option<&str>,
    preselected: Option<&str>,
    accounts_left_square_bracket_right_square_bracket: Option<Vec<i64>>,
) -> Result<Vec<models::ChartDataSet>, Error<GetChartBalanceError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/v1/chart/balance/balance",
        local_var_configuration.base_path
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
    if let Some(ref local_var_str) = period {
        local_var_req_builder =
            local_var_req_builder.query(&[("period", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = preselected {
        local_var_req_builder =
            local_var_req_builder.query(&[("preselected", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = accounts_left_square_bracket_right_square_bracket {
        local_var_req_builder = match "multi" {
            "multi" => local_var_req_builder.query(
                &local_var_str
                    .into_iter()
                    .map(|p| ("accounts[]".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => local_var_req_builder.query(&[(
                "accounts[]",
                &local_var_str
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = x_trace_id {
        local_var_req_builder =
            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetChartBalanceError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}

/// This endpoint returns the data required to generate a chart with basic budget information.
pub async fn get_chart_budget_overview(
    configuration: &configuration::Configuration,
    start: String,
    end: String,
    x_trace_id: Option<&str>,
) -> Result<Vec<models::ChartDataSet>, Error<GetChartBudgetOverviewError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/v1/chart/budget/overview",
        local_var_configuration.base_path
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = x_trace_id {
        local_var_req_builder =
            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetChartBudgetOverviewError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}

/// This endpoint returns the data required to generate a chart with basic category information.
pub async fn get_chart_category_overview(
    configuration: &configuration::Configuration,
    start: String,
    end: String,
    x_trace_id: Option<&str>,
) -> Result<Vec<models::ChartDataSet>, Error<GetChartCategoryOverviewError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/v1/chart/category/overview",
        local_var_configuration.base_path
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = x_trace_id {
        local_var_req_builder =
            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetChartCategoryOverviewError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}