Skip to main content

gusto_api/
earning_type.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct EarningType {
5    pub client: Client,
6}
7
8impl EarningType {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        EarningType { client }
12    }
13
14    /**
15     * Get all earning types for a company.
16     *
17     * This function performs a `GET` to the `/v1/companies/{company_id}/earning_types` endpoint.
18     *
19     * A payroll item in Gusto is associated to an earning type to name the type of earning described by the payroll item.
20     *
21     * #### Default Earning Type
22     * Certain earning types are special because they have tax considerations. Those earning types are mostly the same for every company depending on its legal structure (LLC, Corporation, etc.)
23     *
24     * #### Custom Earning Type
25     * Custom earning types are all the other earning types added specifically for a company.
26     */
27    pub async fn get_company(
28        &self,
29        company_id: &str,
30    ) -> ClientResult<crate::Response<crate::types::EarningTypeListResponse>> {
31        let url = self.client.url(
32            &format!(
33                "/v1/companies/{}/earning_types",
34                crate::progenitor_support::encode_path(company_id),
35            ),
36            None,
37        );
38        self.client
39            .get(
40                &url,
41                crate::Message {
42                    body: None,
43                    content_type: None,
44                },
45            )
46            .await
47    }
48    /**
49     * Create a custom earning type.
50     *
51     * This function performs a `POST` to the `/v1/companies/{company_id}/earning_types` endpoint.
52     *
53     * Create a custom earning type.
54     *
55     * If an inactive earning type exists with the same name, this will reactivate it instead of creating a new one.
56     */
57    pub async fn post_company(
58        &self,
59        company_id: &str,
60        body: &crate::types::PostCompanyEarningTypesRequest,
61    ) -> ClientResult<crate::Response<crate::types::EarningType>> {
62        let url = self.client.url(
63            &format!(
64                "/v1/companies/{}/earning_types",
65                crate::progenitor_support::encode_path(company_id),
66            ),
67            None,
68        );
69        self.client
70            .post(
71                &url,
72                crate::Message {
73                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
74                    content_type: Some("application/json".to_string()),
75                },
76            )
77            .await
78    }
79    /**
80     * Update an earning type.
81     *
82     * This function performs a `PUT` to the `/v1/companies/{company_id}/earning_types/{earning_type_uuid}` endpoint.
83     *
84     * Update an earning type.
85     */
86    pub async fn put_company_type(
87        &self,
88        company_id: &str,
89        earning_type_uuid: &str,
90        body: &crate::types::PutCompanyEarningTypeRequest,
91    ) -> ClientResult<crate::Response<crate::types::EarningType>> {
92        let url = self.client.url(
93            &format!(
94                "/v1/companies/{}/earning_types/{}",
95                crate::progenitor_support::encode_path(company_id),
96                crate::progenitor_support::encode_path(earning_type_uuid),
97            ),
98            None,
99        );
100        self.client
101            .put(
102                &url,
103                crate::Message {
104                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
105                    content_type: Some("application/json".to_string()),
106                },
107            )
108            .await
109    }
110    /**
111     * Deactivate an earning type.
112     *
113     * This function performs a `DELETE` to the `/v1/companies/{company_id}/earning_types/{earning_type_uuid}` endpoint.
114     *
115     * Deactivate an earning type.
116     */
117    pub async fn delete_company_type(
118        &self,
119        company_id: &str,
120        earning_type_uuid: &str,
121    ) -> ClientResult<crate::Response<()>> {
122        let url = self.client.url(
123            &format!(
124                "/v1/companies/{}/earning_types/{}",
125                crate::progenitor_support::encode_path(company_id),
126                crate::progenitor_support::encode_path(earning_type_uuid),
127            ),
128            None,
129        );
130        self.client
131            .delete(
132                &url,
133                crate::Message {
134                    body: None,
135                    content_type: None,
136                },
137            )
138            .await
139    }
140}