ynab_api/apis/
months_api.rs

1/*
2 * YNAB API Endpoints
3 *
4 * Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body.  API Documentation is at https://api.ynab.com
5 *
6 * The version of the OpenAPI document: 1.72.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`get_budget_month`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBudgetMonthError {
22    Status404(models::ErrorResponse),
23    DefaultResponse(models::ErrorResponse),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_budget_months`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetBudgetMonthsError {
31    Status404(models::ErrorResponse),
32    DefaultResponse(models::ErrorResponse),
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Returns a single budget month
38pub async fn get_budget_month(configuration: &configuration::Configuration, budget_id: &str, month: String) -> Result<models::MonthDetailResponse, Error<GetBudgetMonthError>> {
39    let local_var_configuration = configuration;
40
41    let local_var_client = &local_var_configuration.client;
42
43    let local_var_uri_str = format!("{}/budgets/{budget_id}/months/{month}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), month=month);
44    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
45
46    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
47        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
48    }
49    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
50        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
51    };
52
53    let local_var_req = local_var_req_builder.build()?;
54    let local_var_resp = local_var_client.execute(local_var_req).await?;
55
56    let local_var_status = local_var_resp.status();
57    let local_var_content = local_var_resp.text().await?;
58
59    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
60        serde_json::from_str(&local_var_content).map_err(Error::from)
61    } else {
62        let local_var_entity: Option<GetBudgetMonthError> = serde_json::from_str(&local_var_content).ok();
63        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
64        Err(Error::ResponseError(local_var_error))
65    }
66}
67
68/// Returns all budget months
69pub async fn get_budget_months(configuration: &configuration::Configuration, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<models::MonthSummariesResponse, Error<GetBudgetMonthsError>> {
70    let local_var_configuration = configuration;
71
72    let local_var_client = &local_var_configuration.client;
73
74    let local_var_uri_str = format!("{}/budgets/{budget_id}/months", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
75    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
76
77    if let Some(ref local_var_str) = last_knowledge_of_server {
78        local_var_req_builder = local_var_req_builder.query(&[("last_knowledge_of_server", &local_var_str.to_string())]);
79    }
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82    }
83    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
84        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85    };
86
87    let local_var_req = local_var_req_builder.build()?;
88    let local_var_resp = local_var_client.execute(local_var_req).await?;
89
90    let local_var_status = local_var_resp.status();
91    let local_var_content = local_var_resp.text().await?;
92
93    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
94        serde_json::from_str(&local_var_content).map_err(Error::from)
95    } else {
96        let local_var_entity: Option<GetBudgetMonthsError> = serde_json::from_str(&local_var_content).ok();
97        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
98        Err(Error::ResponseError(local_var_error))
99    }
100}
101