Skip to main content

gusto_api/
time_off_requests.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct TimeOffRequests {
5    pub client: Client,
6}
7
8impl TimeOffRequests {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        TimeOffRequests { client }
12    }
13
14    /**
15     * Get time off requests for a company.
16     *
17     * This function performs a `GET` to the `/v1/companies/{company_id}/time_off_requests` endpoint.
18     *
19     * Get all time off requests, past and present, for a company.
20     *
21     * In order to reduce the number of time off requests returned in a single response, or to retrieve time off requests from a time period of interest, you may use the `start_date` and `end_date` parameters.
22     *
23     * You may provide both or either parameters to scope the returned data. For example:
24     *
25     * `?start_date='2019-01-01'`
26     *
27     * Returns all time off requests where the request start date is equal to or after January 1, 2019.
28     *
29     * `?end_date='2019-01-01'`
30     *
31     * Returns all time off requests where the request end date is equal to or before January 1, 2019.
32     *
33     * `?start_date='2019-05-01'&end_date='2019-08-31'`
34     *
35     * Returns all time off requests where the request start date is equal to or after May 1, 2019 and the request end date is equal to or before August 31, 2019.
36     *
37     *
38     * **Parameters:**
39     *
40     * * `start_date: &str` -- Filter time off requests where the request start date is equal to or after this parameter.
41     * * `end_date: &str` -- Filter time off requests where the request end date is equal to or after this parameter.
42     */
43    pub async fn get_company(
44        &self,
45        company_id: &str,
46        start_date: &str,
47        end_date: &str,
48    ) -> ClientResult<crate::Response<Vec<crate::types::TimeOffRequest>>> {
49        let mut query_args: Vec<(String, String)> = Default::default();
50        if !end_date.is_empty() {
51            query_args.push(("end_date".to_string(), end_date.to_string()));
52        }
53        if !start_date.is_empty() {
54            query_args.push(("start_date".to_string(), start_date.to_string()));
55        }
56        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
57        let url = self.client.url(
58            &format!(
59                "/v1/companies/{}/time_off_requests?{}",
60                crate::progenitor_support::encode_path(company_id),
61                query_
62            ),
63            None,
64        );
65        self.client
66            .get(
67                &url,
68                crate::Message {
69                    body: None,
70                    content_type: None,
71                },
72            )
73            .await
74    }
75    /**
76     * Get time off requests for a company.
77     *
78     * This function performs a `GET` to the `/v1/companies/{company_id}/time_off_requests` endpoint.
79     *
80     * As opposed to `get_company`, this function returns all the pages of the request at once.
81     *
82     * Get all time off requests, past and present, for a company.
83     *
84     * In order to reduce the number of time off requests returned in a single response, or to retrieve time off requests from a time period of interest, you may use the `start_date` and `end_date` parameters.
85     *
86     * You may provide both or either parameters to scope the returned data. For example:
87     *
88     * `?start_date='2019-01-01'`
89     *
90     * Returns all time off requests where the request start date is equal to or after January 1, 2019.
91     *
92     * `?end_date='2019-01-01'`
93     *
94     * Returns all time off requests where the request end date is equal to or before January 1, 2019.
95     *
96     * `?start_date='2019-05-01'&end_date='2019-08-31'`
97     *
98     * Returns all time off requests where the request start date is equal to or after May 1, 2019 and the request end date is equal to or before August 31, 2019.
99     *
100     */
101    pub async fn get_all_company(
102        &self,
103        company_id: &str,
104        start_date: &str,
105        end_date: &str,
106    ) -> ClientResult<crate::Response<Vec<crate::types::TimeOffRequest>>> {
107        let mut query_args: Vec<(String, String)> = Default::default();
108        if !end_date.is_empty() {
109            query_args.push(("end_date".to_string(), end_date.to_string()));
110        }
111        if !start_date.is_empty() {
112            query_args.push(("start_date".to_string(), start_date.to_string()));
113        }
114        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
115        let url = self.client.url(
116            &format!(
117                "/v1/companies/{}/time_off_requests?{}",
118                crate::progenitor_support::encode_path(company_id),
119                query_
120            ),
121            None,
122        );
123        self.client
124            .get_all_pages(
125                &url,
126                crate::Message {
127                    body: None,
128                    content_type: None,
129                },
130            )
131            .await
132    }
133    /**
134     * Get a specific time off request.
135     *
136     * This function performs a `GET` to the `/v1/companies/{company_id}/time_off_requests/{time_off_request_id}` endpoint.
137     *
138     * Details of a single time off request
139     */
140    pub async fn get_company_request(
141        &self,
142        company_id: &str,
143        time_off_request_id: &str,
144    ) -> ClientResult<crate::Response<crate::types::TimeOffRequest>> {
145        let url = self.client.url(
146            &format!(
147                "/v1/companies/{}/time_off_requests/{}",
148                crate::progenitor_support::encode_path(company_id),
149                crate::progenitor_support::encode_path(time_off_request_id),
150            ),
151            None,
152        );
153        self.client
154            .get(
155                &url,
156                crate::Message {
157                    body: None,
158                    content_type: None,
159                },
160            )
161            .await
162    }
163}