ynab_api_async_fork/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.1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::rc::Rc;
12use std::borrow::Borrow;
13#[allow(unused_imports)]
14use std::option::Option;
15
16use reqwest;
17
18use super::{Error, configuration};
19
20pub struct MonthsApiClient {
21    configuration: Rc<configuration::Configuration>,
22}
23
24impl MonthsApiClient {
25    pub fn new(configuration: Rc<configuration::Configuration>) -> MonthsApiClient {
26        MonthsApiClient {
27            configuration,
28        }
29    }
30}
31
32pub trait MonthsApi {
33    fn get_budget_month(&self, budget_id: &str, month: String) -> Result<crate::models::MonthDetailResponse, Error>;
34    fn get_budget_months(&self, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<crate::models::MonthSummariesResponse, Error>;
35}
36
37impl MonthsApi for MonthsApiClient {
38    fn get_budget_month(&self, budget_id: &str, month: String) -> Result<crate::models::MonthDetailResponse, Error> {
39        let configuration: &configuration::Configuration = self.configuration.borrow();
40        let client = &configuration.client;
41
42        let uri_str = format!("{}/budgets/{budget_id}/months/{month}", configuration.base_path, budget_id=crate::apis::urlencode(budget_id), month=month);
43        let mut req_builder = client.get(uri_str.as_str());
44
45        if let Some(ref user_agent) = configuration.user_agent {
46            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
47        }
48        if let Some(ref token) = configuration.bearer_access_token {
49            req_builder = req_builder.bearer_auth(token.to_owned());
50        };
51
52        // send request
53        let req = req_builder.build()?;
54
55        Ok(client.execute(req)?.error_for_status()?.json()?)
56    }
57
58    fn get_budget_months(&self, budget_id: &str, last_knowledge_of_server: Option<i64>) -> Result<crate::models::MonthSummariesResponse, Error> {
59        let configuration: &configuration::Configuration = self.configuration.borrow();
60        let client = &configuration.client;
61
62        let uri_str = format!("{}/budgets/{budget_id}/months", configuration.base_path, budget_id=crate::apis::urlencode(budget_id));
63        let mut req_builder = client.get(uri_str.as_str());
64
65        if let Some(ref s) = last_knowledge_of_server {
66            req_builder = req_builder.query(&[("last_knowledge_of_server", &s.to_string())]);
67        }
68        if let Some(ref user_agent) = configuration.user_agent {
69            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70        }
71        if let Some(ref token) = configuration.bearer_access_token {
72            req_builder = req_builder.bearer_auth(token.to_owned());
73        };
74
75        // send request
76        let req = req_builder.build()?;
77
78        Ok(client.execute(req)?.error_for_status()?.json()?)
79    }
80
81}