ynab_api/apis/
budgets_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBudgetByIdError {
22 Status404(models::ErrorResponse),
23 DefaultResponse(models::ErrorResponse),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetBudgetSettingsByIdError {
31 Status404(models::ErrorResponse),
32 DefaultResponse(models::ErrorResponse),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetBudgetsError {
40 Status404(models::ErrorResponse),
41 DefaultResponse(models::ErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45
46pub async fn get_budget_by_id(configuration: &configuration::Configuration, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<models::BudgetDetailResponse, Error<GetBudgetByIdError>> {
48 let local_var_configuration = configuration;
49
50 let local_var_client = &local_var_configuration.client;
51
52 let local_var_uri_str = format!("{}/budgets/{budget_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
53 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
54
55 if let Some(ref local_var_str) = last_knowledge_of_server {
56 local_var_req_builder = local_var_req_builder.query(&[("last_knowledge_of_server", &local_var_str.to_string())]);
57 }
58 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
59 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60 }
61 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
62 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
63 };
64
65 let local_var_req = local_var_req_builder.build()?;
66 let local_var_resp = local_var_client.execute(local_var_req).await?;
67
68 let local_var_status = local_var_resp.status();
69 let local_var_content = local_var_resp.text().await?;
70
71 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
72 serde_json::from_str(&local_var_content).map_err(Error::from)
73 } else {
74 let local_var_entity: Option<GetBudgetByIdError> = serde_json::from_str(&local_var_content).ok();
75 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
76 Err(Error::ResponseError(local_var_error))
77 }
78}
79
80pub async fn get_budget_settings_by_id(configuration: &configuration::Configuration, budget_id: &str) -> Result<models::BudgetSettingsResponse, Error<GetBudgetSettingsByIdError>> {
82 let local_var_configuration = configuration;
83
84 let local_var_client = &local_var_configuration.client;
85
86 let local_var_uri_str = format!("{}/budgets/{budget_id}/settings", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
87 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
88
89 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
90 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
91 }
92 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
93 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
94 };
95
96 let local_var_req = local_var_req_builder.build()?;
97 let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99 let local_var_status = local_var_resp.status();
100 let local_var_content = local_var_resp.text().await?;
101
102 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103 serde_json::from_str(&local_var_content).map_err(Error::from)
104 } else {
105 let local_var_entity: Option<GetBudgetSettingsByIdError> = serde_json::from_str(&local_var_content).ok();
106 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
107 Err(Error::ResponseError(local_var_error))
108 }
109}
110
111pub async fn get_budgets(configuration: &configuration::Configuration, include_accounts: Option<bool>) -> Result<models::BudgetSummaryResponse, Error<GetBudgetsError>> {
113 let local_var_configuration = configuration;
114
115 let local_var_client = &local_var_configuration.client;
116
117 let local_var_uri_str = format!("{}/budgets", local_var_configuration.base_path);
118 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
119
120 if let Some(ref local_var_str) = include_accounts {
121 local_var_req_builder = local_var_req_builder.query(&[("include_accounts", &local_var_str.to_string())]);
122 }
123 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
124 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
125 }
126 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
127 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
128 };
129
130 let local_var_req = local_var_req_builder.build()?;
131 let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133 let local_var_status = local_var_resp.status();
134 let local_var_content = local_var_resp.text().await?;
135
136 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137 serde_json::from_str(&local_var_content).map_err(Error::from)
138 } else {
139 let local_var_entity: Option<GetBudgetsError> = serde_json::from_str(&local_var_content).ok();
140 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141 Err(Error::ResponseError(local_var_error))
142 }
143}
144