remote_api/
employments.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Employments {
6    pub client: Client,
7}
8
9impl Employments {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List employments\n\nLists all employments, except for the deleted ones.\n\nThis endpoint requires and returns country-specific data. The exact required and returned fields will\nvary depending on which country the employment is in. To see the list of parameters for each country,\nsee the **Show form schema** endpoint under the [Countries](#tag/Countries) category.\n\nPlease note that the compliance requirements for each country are subject to change, which will result\nin required and optional parameters being added and deleted without notice.\n\nIf you are using this endpoint to build an integration, make sure you are dynamically collecting or\ndisplaying the latest parameters for each country by querying the _\"Show form schema\"_ endpoint.\n\nFor more information on JSON Schemas, see the **How JSON Schemas work** documentation.\n\nTo learn how you can dynamically generate forms to display in your UI, see the documentation for\nthe [json-schema-form](https://www.notion.so/remotecom/json-schema-form-Documentation-4f390236948b4b2e8b7350ebcd488ca6) tool.\n\n\n\n**Parameters:**\n\n- `company_id: Option<String>`: Company ID\n- `page: Option<i64>`: Starts fetching records after the given page\n- `page_size: Option<i64>`: Change the amount of records returned per page, defaults to 20, limited to 100\n\n```rust,no_run\nasync fn example_employments_get_index() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::ListEmploymentsResponse = client\n        .employments()\n        .get_index(\n            Some(\"some-string\".to_string()),\n            Some(4 as i64),\n            Some(4 as i64),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
16    #[tracing::instrument]
17    pub async fn get_index<'a>(
18        &'a self,
19        company_id: Option<String>,
20        page: Option<i64>,
21        page_size: Option<i64>,
22    ) -> Result<crate::types::ListEmploymentsResponse, crate::types::error::Error> {
23        let mut req = self.client.client.request(
24            http::Method::GET,
25            format!("{}/{}", self.client.base_url, "v1/employments"),
26        );
27        req = req.bearer_auth(&self.client.token);
28        let mut query_params = vec![];
29        if let Some(p) = company_id {
30            query_params.push(("company_id", p));
31        }
32
33        if let Some(p) = page {
34            query_params.push(("page", format!("{}", p)));
35        }
36
37        if let Some(p) = page_size {
38            query_params.push(("page_size", format!("{}", p)));
39        }
40
41        req = req.query(&query_params);
42        let resp = req.send().await?;
43        let status = resp.status();
44        if status.is_success() {
45            let text = resp.text().await.unwrap_or_default();
46            serde_json::from_str(&text).map_err(|err| {
47                crate::types::error::Error::from_serde_error(
48                    format_serde_error::SerdeError::new(text.to_string(), err),
49                    status,
50                )
51            })
52        } else {
53            let text = resp.text().await.unwrap_or_default();
54            Err(crate::types::error::Error::Server {
55                body: text.to_string(),
56                status,
57            })
58        }
59    }
60
61    #[doc = "Create employment\n\nCreates an employment. We support creating employees and contractors.\n\nThis endpoint requires and returns country-specific data. The exact required and returned fields will\nvary depending on which country the employment is in. To see the list of parameters for each country,\nsee the **Show form schema** endpoint under the [Countries](#tag/Countries) category.\n\nPlease note that the compliance requirements for each country are subject to change, which will result\nin required and optional parameters being added and deleted without notice.\n\nIf you are using this endpoint to build an integration, make sure you are dynamically collecting or\ndisplaying the latest parameters for each country by querying the _\"Show form schema\"_ endpoint.\n\nFor more information on JSON Schemas, see the **How JSON Schemas work** documentation.\n\nTo learn how you can dynamically generate forms to display in your UI, see the documentation for\nthe [json-schema-form](https://www.notion.so/remotecom/json-schema-form-Documentation-4f390236948b4b2e8b7350ebcd488ca6) tool.\n\n\n\n```rust,no_run\nasync fn example_employments_post_create() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::EmploymentResponse = client\n        .employments()\n        .post_create(&remote_api::types::EmploymentBasicParams {\n            company_id: \"some-string\".to_string(),\n            country_code: Some(\"some-string\".to_string()),\n            full_name: \"some-string\".to_string(),\n            job_title: Some(\"some-string\".to_string()),\n            personal_email: \"email@example.com\".to_string(),\n            provisional_start_date: Some(chrono::Utc::now().date_naive()),\n            type_: remote_api::types::EmploymentBasicParamsType::Contractor,\n        })\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
62    #[tracing::instrument]
63    pub async fn post_create<'a>(
64        &'a self,
65        body: &crate::types::EmploymentBasicParams,
66    ) -> Result<crate::types::EmploymentResponse, crate::types::error::Error> {
67        let mut req = self.client.client.request(
68            http::Method::POST,
69            format!("{}/{}", self.client.base_url, "v1/employments"),
70        );
71        req = req.bearer_auth(&self.client.token);
72        req = req.json(body);
73        let resp = req.send().await?;
74        let status = resp.status();
75        if status.is_success() {
76            let text = resp.text().await.unwrap_or_default();
77            serde_json::from_str(&text).map_err(|err| {
78                crate::types::error::Error::from_serde_error(
79                    format_serde_error::SerdeError::new(text.to_string(), err),
80                    status,
81                )
82            })
83        } else {
84            let text = resp.text().await.unwrap_or_default();
85            Err(crate::types::error::Error::Server {
86                body: text.to_string(),
87                status,
88            })
89        }
90    }
91
92    #[doc = "Show employment\n\nShows all the information of an employment.\n\nThis endpoint requires and returns country-specific data. The exact required and returned fields will\nvary depending on which country the employment is in. To see the list of parameters for each country,\nsee the **Show form schema** endpoint under the [Countries](#tag/Countries) category.\n\nPlease note that the compliance requirements for each country are subject to change, which will result\nin required and optional parameters being added and deleted without notice.\n\nIf you are using this endpoint to build an integration, make sure you are dynamically collecting or\ndisplaying the latest parameters for each country by querying the _\"Show form schema\"_ endpoint.\n\nFor more information on JSON Schemas, see the **How JSON Schemas work** documentation.\n\nTo learn how you can dynamically generate forms to display in your UI, see the documentation for\nthe [json-schema-form](https://www.notion.so/remotecom/json-schema-form-Documentation-4f390236948b4b2e8b7350ebcd488ca6) tool.\n\n\n\n**Parameters:**\n\n- `employment_id: &'astr`: Employment ID (required)\n\n```rust,no_run\nasync fn example_employments_get_show() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::EmploymentResponse =\n        client.employments().get_show(\"some-string\").await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
93    #[tracing::instrument]
94    pub async fn get_show<'a>(
95        &'a self,
96        employment_id: &'a str,
97    ) -> Result<crate::types::EmploymentResponse, crate::types::error::Error> {
98        let mut req = self.client.client.request(
99            http::Method::GET,
100            format!(
101                "{}/{}",
102                self.client.base_url,
103                "v1/employments/{employment_id}".replace("{employment_id}", employment_id)
104            ),
105        );
106        req = req.bearer_auth(&self.client.token);
107        let resp = req.send().await?;
108        let status = resp.status();
109        if status.is_success() {
110            let text = resp.text().await.unwrap_or_default();
111            serde_json::from_str(&text).map_err(|err| {
112                crate::types::error::Error::from_serde_error(
113                    format_serde_error::SerdeError::new(text.to_string(), err),
114                    status,
115                )
116            })
117        } else {
118            let text = resp.text().await.unwrap_or_default();
119            Err(crate::types::error::Error::Server {
120                body: text.to_string(),
121                status,
122            })
123        }
124    }
125
126    #[doc = "Update employment\n\nUpdates an employment.\n\n**For `created` employments:** You can change all basic params and onboarding tasks or perform a per onboarding task update.\n\n**For `active` employments:** At this stage, it is only allowed to update the manager (`manager_id` field).\n\nThis endpoint requires and returns country-specific data. The exact required and returned fields will\nvary depending on which country the employment is in. To see the list of parameters for each country,\nsee the **Show form schema** endpoint under the [Countries](#tag/Countries) category.\n\nPlease note that the compliance requirements for each country are subject to change, which will result\nin required and optional parameters being added and deleted without notice.\n\nIf you are using this endpoint to build an integration, make sure you are dynamically collecting or\ndisplaying the latest parameters for each country by querying the _\"Show form schema\"_ endpoint.\n\nFor more information on JSON Schemas, see the **How JSON Schemas work** documentation.\n\nTo learn how you can dynamically generate forms to display in your UI, see the documentation for\nthe [json-schema-form](https://www.notion.so/remotecom/json-schema-form-Documentation-4f390236948b4b2e8b7350ebcd488ca6) tool.\n\n\nPlease contact Remote if you need to update contractors via API since it's currently not supported.\n\n\n**Parameters:**\n\n- `employment_id: &'astr`: Employment ID (required)\n\n```rust,no_run\nasync fn example_employments_patch_update_2() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::EmploymentResponse = client\n        .employments()\n        .patch_update_2(\n            \"some-string\",\n            &remote_api::types::EmploymentFullParams {\n                address_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                administrative_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                bank_account_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                billing_address_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                company_id: \"some-string\".to_string(),\n                contract_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                country: Some(remote_api::types::Country {\n                    code: \"some-string\".to_string(),\n                    country_subdivisions: Some(vec![remote_api::types::CountrySubdivision {\n                        code: Some(\"some-string\".to_string()),\n                        name: \"some-string\".to_string(),\n                        subdivision_type: Some(\"some-string\".to_string()),\n                    }]),\n                    name: \"some-string\".to_string(),\n                }),\n                emergency_contact_details: Some(serde_json::Value::String(\n                    \"some-string\".to_string(),\n                )),\n                full_name: \"some-string\".to_string(),\n                job_title: Some(\"some-string\".to_string()),\n                manager_id: Some(\"some-string\".to_string()),\n                personal_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                personal_email: \"some-string\".to_string(),\n                pricing_plan_details: Some(remote_api::types::PricingPlanDetails {\n                    frequency: \"some-string\".to_string(),\n                }),\n                provisional_start_date: Some(chrono::Utc::now().date_naive()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
127    #[tracing::instrument]
128    pub async fn patch_update_2<'a>(
129        &'a self,
130        employment_id: &'a str,
131        body: &crate::types::EmploymentFullParams,
132    ) -> Result<crate::types::EmploymentResponse, crate::types::error::Error> {
133        let mut req = self.client.client.request(
134            http::Method::PUT,
135            format!(
136                "{}/{}",
137                self.client.base_url,
138                "v1/employments/{employment_id}".replace("{employment_id}", employment_id)
139            ),
140        );
141        req = req.bearer_auth(&self.client.token);
142        req = req.json(body);
143        let resp = req.send().await?;
144        let status = resp.status();
145        if status.is_success() {
146            let text = resp.text().await.unwrap_or_default();
147            serde_json::from_str(&text).map_err(|err| {
148                crate::types::error::Error::from_serde_error(
149                    format_serde_error::SerdeError::new(text.to_string(), err),
150                    status,
151                )
152            })
153        } else {
154            let text = resp.text().await.unwrap_or_default();
155            Err(crate::types::error::Error::Server {
156                body: text.to_string(),
157                status,
158            })
159        }
160    }
161
162    #[doc = "Update employment\n\nUpdates an employment.\n\n**For `created` employments:** You can change all basic params and onboarding tasks or perform a per onboarding task update.\n\n**For `active` employments:** At this stage, it is only allowed to update the manager (`manager_id` field).\n\nThis endpoint requires and returns country-specific data. The exact required and returned fields will\nvary depending on which country the employment is in. To see the list of parameters for each country,\nsee the **Show form schema** endpoint under the [Countries](#tag/Countries) category.\n\nPlease note that the compliance requirements for each country are subject to change, which will result\nin required and optional parameters being added and deleted without notice.\n\nIf you are using this endpoint to build an integration, make sure you are dynamically collecting or\ndisplaying the latest parameters for each country by querying the _\"Show form schema\"_ endpoint.\n\nFor more information on JSON Schemas, see the **How JSON Schemas work** documentation.\n\nTo learn how you can dynamically generate forms to display in your UI, see the documentation for\nthe [json-schema-form](https://www.notion.so/remotecom/json-schema-form-Documentation-4f390236948b4b2e8b7350ebcd488ca6) tool.\n\n\nPlease contact Remote if you need to update contractors via API since it's currently not supported.\n\n\n**Parameters:**\n\n- `employment_id: &'astr`: Employment ID (required)\n\n```rust,no_run\nasync fn example_employments_patch_update() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::EmploymentResponse = client\n        .employments()\n        .patch_update(\n            \"some-string\",\n            &remote_api::types::EmploymentFullParams {\n                address_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                administrative_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                bank_account_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                billing_address_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                company_id: \"some-string\".to_string(),\n                contract_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                country: Some(remote_api::types::Country {\n                    code: \"some-string\".to_string(),\n                    country_subdivisions: Some(vec![remote_api::types::CountrySubdivision {\n                        code: Some(\"some-string\".to_string()),\n                        name: \"some-string\".to_string(),\n                        subdivision_type: Some(\"some-string\".to_string()),\n                    }]),\n                    name: \"some-string\".to_string(),\n                }),\n                emergency_contact_details: Some(serde_json::Value::String(\n                    \"some-string\".to_string(),\n                )),\n                full_name: \"some-string\".to_string(),\n                job_title: Some(\"some-string\".to_string()),\n                manager_id: Some(\"some-string\".to_string()),\n                personal_details: Some(serde_json::Value::String(\"some-string\".to_string())),\n                personal_email: \"some-string\".to_string(),\n                pricing_plan_details: Some(remote_api::types::PricingPlanDetails {\n                    frequency: \"some-string\".to_string(),\n                }),\n                provisional_start_date: Some(chrono::Utc::now().date_naive()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
163    #[tracing::instrument]
164    pub async fn patch_update<'a>(
165        &'a self,
166        employment_id: &'a str,
167        body: &crate::types::EmploymentFullParams,
168    ) -> Result<crate::types::EmploymentResponse, crate::types::error::Error> {
169        let mut req = self.client.client.request(
170            http::Method::PATCH,
171            format!(
172                "{}/{}",
173                self.client.base_url,
174                "v1/employments/{employment_id}".replace("{employment_id}", employment_id)
175            ),
176        );
177        req = req.bearer_auth(&self.client.token);
178        req = req.json(body);
179        let resp = req.send().await?;
180        let status = resp.status();
181        if status.is_success() {
182            let text = resp.text().await.unwrap_or_default();
183            serde_json::from_str(&text).map_err(|err| {
184                crate::types::error::Error::from_serde_error(
185                    format_serde_error::SerdeError::new(text.to_string(), err),
186                    status,
187                )
188            })
189        } else {
190            let text = resp.text().await.unwrap_or_default();
191            Err(crate::types::error::Error::Server {
192                body: text.to_string(),
193                status,
194            })
195        }
196    }
197}