ynab_api/apis/
payees_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 GetPayeeByIdError {
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 GetPayeesError {
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 UpdatePayeeError {
40 Status400(models::ErrorResponse),
41 UnknownValue(serde_json::Value),
42}
43
44
45pub async fn get_payee_by_id(configuration: &configuration::Configuration, budget_id: &str, payee_id: &str) -> Result<models::PayeeResponse, Error<GetPayeeByIdError>> {
47 let local_var_configuration = configuration;
48
49 let local_var_client = &local_var_configuration.client;
50
51 let local_var_uri_str = format!("{}/budgets/{budget_id}/payees/{payee_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), payee_id=crate::apis::urlencode(payee_id));
52 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
53
54 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
55 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
56 }
57 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
58 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
59 };
60
61 let local_var_req = local_var_req_builder.build()?;
62 let local_var_resp = local_var_client.execute(local_var_req).await?;
63
64 let local_var_status = local_var_resp.status();
65 let local_var_content = local_var_resp.text().await?;
66
67 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
68 serde_json::from_str(&local_var_content).map_err(Error::from)
69 } else {
70 let local_var_entity: Option<GetPayeeByIdError> = serde_json::from_str(&local_var_content).ok();
71 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
72 Err(Error::ResponseError(local_var_error))
73 }
74}
75
76pub async fn get_payees(configuration: &configuration::Configuration, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<models::PayeesResponse, Error<GetPayeesError>> {
78 let local_var_configuration = configuration;
79
80 let local_var_client = &local_var_configuration.client;
81
82 let local_var_uri_str = format!("{}/budgets/{budget_id}/payees", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
83 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
84
85 if let Some(ref local_var_str) = last_knowledge_of_server {
86 local_var_req_builder = local_var_req_builder.query(&[("last_knowledge_of_server", &local_var_str.to_string())]);
87 }
88 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90 }
91 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
92 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
93 };
94
95 let local_var_req = local_var_req_builder.build()?;
96 let local_var_resp = local_var_client.execute(local_var_req).await?;
97
98 let local_var_status = local_var_resp.status();
99 let local_var_content = local_var_resp.text().await?;
100
101 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102 serde_json::from_str(&local_var_content).map_err(Error::from)
103 } else {
104 let local_var_entity: Option<GetPayeesError> = serde_json::from_str(&local_var_content).ok();
105 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
106 Err(Error::ResponseError(local_var_error))
107 }
108}
109
110pub async fn update_payee(configuration: &configuration::Configuration, budget_id: &str, payee_id: &str, data: models::PatchPayeeWrapper) -> Result<models::SavePayeeResponse, Error<UpdatePayeeError>> {
112 let local_var_configuration = configuration;
113
114 let local_var_client = &local_var_configuration.client;
115
116 let local_var_uri_str = format!("{}/budgets/{budget_id}/payees/{payee_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), payee_id=crate::apis::urlencode(payee_id));
117 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, 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 = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
121 }
122 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
123 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
124 };
125 local_var_req_builder = local_var_req_builder.json(&data);
126
127 let local_var_req = local_var_req_builder.build()?;
128 let local_var_resp = local_var_client.execute(local_var_req).await?;
129
130 let local_var_status = local_var_resp.status();
131 let local_var_content = local_var_resp.text().await?;
132
133 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
134 serde_json::from_str(&local_var_content).map_err(Error::from)
135 } else {
136 let local_var_entity: Option<UpdatePayeeError> = serde_json::from_str(&local_var_content).ok();
137 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
138 Err(Error::ResponseError(local_var_error))
139 }
140}
141