gusto_api/
locations.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Locations {
5    pub client: Client,
6}
7
8impl Locations {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Locations { client }
12    }
13
14    /**
15     * Get company locations.
16     *
17     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/locations` endpoint.
18     *
19     * Company locations represent all addresses associated with a company. These can be filing addesses, mailing addresses, and/or work locations; one address may serve multiple, or all, purposes.
20     *
21     * Since all company locations are subsets of locations, retrieving or updating an individual record should be done via the locations endpoints.
22     */
23    pub async fn get_company(
24        &self,
25        company_id_or_uuid: &str,
26    ) -> ClientResult<crate::Response<Vec<crate::types::Location>>> {
27        let url = self.client.url(
28            &format!(
29                "/v1/companies/{}/locations",
30                crate::progenitor_support::encode_path(company_id_or_uuid),
31            ),
32            None,
33        );
34        self.client
35            .get(
36                &url,
37                crate::Message {
38                    body: None,
39                    content_type: None,
40                },
41            )
42            .await
43    }
44    /**
45     * Get company locations.
46     *
47     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/locations` endpoint.
48     *
49     * As opposed to `get_company`, this function returns all the pages of the request at once.
50     *
51     * Company locations represent all addresses associated with a company. These can be filing addesses, mailing addresses, and/or work locations; one address may serve multiple, or all, purposes.
52     *
53     * Since all company locations are subsets of locations, retrieving or updating an individual record should be done via the locations endpoints.
54     */
55    pub async fn get_all_company(
56        &self,
57        company_id_or_uuid: &str,
58    ) -> ClientResult<crate::Response<Vec<crate::types::Location>>> {
59        let url = self.client.url(
60            &format!(
61                "/v1/companies/{}/locations",
62                crate::progenitor_support::encode_path(company_id_or_uuid),
63            ),
64            None,
65        );
66        self.client
67            .get_all_pages(
68                &url,
69                crate::Message {
70                    body: None,
71                    content_type: None,
72                },
73            )
74            .await
75    }
76    /**
77     * Create a company location.
78     *
79     * This function performs a `POST` to the `/v1/companies/{company_id_or_uuid}/locations` endpoint.
80     *
81     * Company locations represent all addresses associated with a company. These can be filing addesses, mailing addresses, and/or work locations; one address may serve multiple, or all, purposes.
82     *
83     * Since all company locations are subsets of locations, retrieving or updating an individual record should be done via the locations endpoints.
84     */
85    pub async fn post_company(
86        &self,
87        company_id_or_uuid: &str,
88        body: &crate::types::PostCompanyLocationsRequest,
89    ) -> ClientResult<crate::Response<crate::types::Location>> {
90        let url = self.client.url(
91            &format!(
92                "/v1/companies/{}/locations",
93                crate::progenitor_support::encode_path(company_id_or_uuid),
94            ),
95            None,
96        );
97        self.client
98            .post(
99                &url,
100                crate::Message {
101                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
102                    content_type: Some("application/json".to_string()),
103                },
104            )
105            .await
106    }
107    /**
108     * Get a location.
109     *
110     * This function performs a `GET` to the `/v1/locations/{location_id}` endpoint.
111     *
112     * Get a location.
113     */
114    pub async fn get(
115        &self,
116        location_id: &str,
117    ) -> ClientResult<crate::Response<crate::types::Location>> {
118        let url = self.client.url(
119            &format!(
120                "/v1/locations/{}",
121                crate::progenitor_support::encode_path(location_id),
122            ),
123            None,
124        );
125        self.client
126            .get(
127                &url,
128                crate::Message {
129                    body: None,
130                    content_type: None,
131                },
132            )
133            .await
134    }
135    /**
136     * Update a location.
137     *
138     * This function performs a `PUT` to the `/v1/locations/{location_id}` endpoint.
139     *
140     * Update a location.
141     */
142    pub async fn put(
143        &self,
144        location_id: &str,
145        body: &crate::types::PutLocationRequest,
146    ) -> ClientResult<crate::Response<crate::types::Location>> {
147        let url = self.client.url(
148            &format!(
149                "/v1/locations/{}",
150                crate::progenitor_support::encode_path(location_id),
151            ),
152            None,
153        );
154        self.client
155            .put(
156                &url,
157                crate::Message {
158                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
159                    content_type: Some("application/json".to_string()),
160                },
161            )
162            .await
163    }
164}