ynab_api/apis/
payee_locations_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_payee_location_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetPayeeLocationByIdError {
22    Status404(models::ErrorResponse),
23    DefaultResponse(models::ErrorResponse),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_payee_locations`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetPayeeLocationsError {
31    Status404(models::ErrorResponse),
32    DefaultResponse(models::ErrorResponse),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_payee_locations_by_payee`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetPayeeLocationsByPayeeError {
40    Status404(models::ErrorResponse),
41    DefaultResponse(models::ErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45
46/// Returns a single payee location
47pub async fn get_payee_location_by_id(configuration: &configuration::Configuration, budget_id: &str, payee_location_id: &str) -> Result<models::PayeeLocationResponse, Error<GetPayeeLocationByIdError>> {
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}/payee_locations/{payee_location_id}", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), payee_location_id=crate::apis::urlencode(payee_location_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_user_agent) = local_var_configuration.user_agent {
56        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
57    }
58    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
59        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
60    };
61
62    let local_var_req = local_var_req_builder.build()?;
63    let local_var_resp = local_var_client.execute(local_var_req).await?;
64
65    let local_var_status = local_var_resp.status();
66    let local_var_content = local_var_resp.text().await?;
67
68    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69        serde_json::from_str(&local_var_content).map_err(Error::from)
70    } else {
71        let local_var_entity: Option<GetPayeeLocationByIdError> = serde_json::from_str(&local_var_content).ok();
72        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
73        Err(Error::ResponseError(local_var_error))
74    }
75}
76
77/// Returns all payee locations
78pub async fn get_payee_locations(configuration: &configuration::Configuration, budget_id: &str) -> Result<models::PayeeLocationsResponse, Error<GetPayeeLocationsError>> {
79    let local_var_configuration = configuration;
80
81    let local_var_client = &local_var_configuration.client;
82
83    let local_var_uri_str = format!("{}/budgets/{budget_id}/payee_locations", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
84    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
85
86    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
87        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
88    }
89    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
90        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
91    };
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<GetPayeeLocationsError> = serde_json::from_str(&local_var_content).ok();
103        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
104        Err(Error::ResponseError(local_var_error))
105    }
106}
107
108/// Returns all payee locations for a specified payee
109pub async fn get_payee_locations_by_payee(configuration: &configuration::Configuration, budget_id: &str, payee_id: &str) -> Result<models::PayeeLocationsResponse, Error<GetPayeeLocationsByPayeeError>> {
110    let local_var_configuration = configuration;
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!("{}/budgets/{budget_id}/payees/{payee_id}/payee_locations", local_var_configuration.base_path, budget_id=crate::apis::urlencode(budget_id), payee_id=crate::apis::urlencode(payee_id));
115    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
116
117    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
119    }
120    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
121        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
122    };
123
124    let local_var_req = local_var_req_builder.build()?;
125    let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127    let local_var_status = local_var_resp.status();
128    let local_var_content = local_var_resp.text().await?;
129
130    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131        serde_json::from_str(&local_var_content).map_err(Error::from)
132    } else {
133        let local_var_entity: Option<GetPayeeLocationsByPayeeError> = serde_json::from_str(&local_var_content).ok();
134        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135        Err(Error::ResponseError(local_var_error))
136    }
137}
138