remote_api/
company_managers.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct CompanyManagers {
6    pub client: Client,
7}
8
9impl CompanyManagers {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List Company Managers\n\nList all company managers of an integration. If filtered by \
16             the company_id param,\nit lists only company managers belonging to the specified \
17             company.\n\n\n**Parameters:**\n\n- `company_id: Option<String>`: A Company ID to \
18             filter the results (only applicable for Integration Partners).\n- `page: \
19             Option<i64>`: Starts fetching records after the given page\n- `page_size: \
20             Option<i64>`: Change the amount of records returned per page, defaults to 20, limited \
21             to 100\n\n```rust,no_run\nasync fn example_company_managers_get_index() -> \
22             anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let \
23             result: remote_api::types::CompanyManagersResponse = client\n        \
24             .company_managers()\n        .get_index(\n            \
25             Some(\"some-string\".to_string()),\n            Some(4 as i64),\n            Some(4 \
26             as i64),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    \
27             Ok(())\n}\n```"]
28    #[tracing::instrument]
29    pub async fn get_index<'a>(
30        &'a self,
31        company_id: Option<String>,
32        page: Option<i64>,
33        page_size: Option<i64>,
34    ) -> Result<crate::types::CompanyManagersResponse, crate::types::error::Error> {
35        let mut req = self.client.client.request(
36            http::Method::GET,
37            format!("{}/{}", self.client.base_url, "v1/company-managers"),
38        );
39        req = req.bearer_auth(&self.client.token);
40        let mut query_params = vec![];
41        if let Some(p) = company_id {
42            query_params.push(("company_id", p));
43        }
44
45        if let Some(p) = page {
46            query_params.push(("page", format!("{}", p)));
47        }
48
49        if let Some(p) = page_size {
50            query_params.push(("page_size", format!("{}", p)));
51        }
52
53        req = req.query(&query_params);
54        let resp = req.send().await?;
55        let status = resp.status();
56        if status.is_success() {
57            let text = resp.text().await.unwrap_or_default();
58            serde_json::from_str(&text).map_err(|err| {
59                crate::types::error::Error::from_serde_error(
60                    format_serde_error::SerdeError::new(text.to_string(), err),
61                    status,
62                )
63            })
64        } else {
65            let text = resp.text().await.unwrap_or_default();
66            Err(crate::types::error::Error::Server {
67                body: text.to_string(),
68                status,
69            })
70        }
71    }
72
73    #[doc = "Create and invite a Company Manager\n\nCreate a Company Manager and sends the invitation email for signing in to the Remote Platform.\n\n```rust,no_run\nasync fn example_company_managers_post_create() -> anyhow::Result<()> {\n    let client = remote_api::Client::new_from_env();\n    let result: remote_api::types::CompanyManagerCreatedResponse = client\n        .company_managers()\n        .post_create(&remote_api::types::CompanyManagerParams {\n            company_id: Some(\"some-string\".to_string()),\n            email: \"email@example.com\".to_string(),\n            name: \"some-string\".to_string(),\n            role: \"some-string\".to_string(),\n        })\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
74    #[tracing::instrument]
75    pub async fn post_create<'a>(
76        &'a self,
77        body: &crate::types::CompanyManagerParams,
78    ) -> Result<crate::types::CompanyManagerCreatedResponse, crate::types::error::Error> {
79        let mut req = self.client.client.request(
80            http::Method::POST,
81            format!("{}/{}", self.client.base_url, "v1/company-managers"),
82        );
83        req = req.bearer_auth(&self.client.token);
84        req = req.json(body);
85        let resp = req.send().await?;
86        let status = resp.status();
87        if status.is_success() {
88            let text = resp.text().await.unwrap_or_default();
89            serde_json::from_str(&text).map_err(|err| {
90                crate::types::error::Error::from_serde_error(
91                    format_serde_error::SerdeError::new(text.to_string(), err),
92                    status,
93                )
94            })
95        } else {
96            let text = resp.text().await.unwrap_or_default();
97            Err(crate::types::error::Error::Server {
98                body: text.to_string(),
99                status,
100            })
101        }
102    }
103}