front_api/
links.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Links {
6    pub client: Client,
7}
8
9impl Links {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List link conversations\n\nList the conversations linked to a specific link. For more advanced filtering, see the [search endpoint](https://dev.frontapp.com/reference/conversations#search-conversations).\n> ⚠\u{fe0f} Deprecated field included\n>\n> This endpoint returns a deprecated `last_message` field in the top-level conversation bodies listed. Please use the\n> `_links.related.last_message` field instead.\n\n\n**Parameters:**\n\n- `limit: Option<i64>`: Max number of results per page\n- `link_id: &'astr`: The Link ID (required)\n- `page_token: Option<String>`: Token to use to request the next page\n- `q: Option<String>`: Search query object with a property `statuses`, whose value should be a list of conversation statuses (`assigned`, `unassigned`, `archived`, or `deleted`).\n\n```rust,no_run\nasync fn example_links_list_conversations() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::ListLinkConversationsResponse = client\n        .links()\n        .list_conversations(\n            Some(4 as i64),\n            \"some-string\",\n            Some(\"some-string\".to_string()),\n            Some(\"some-string\".to_string()),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
16    #[tracing::instrument]
17    pub async fn list_conversations<'a>(
18        &'a self,
19        limit: Option<i64>,
20        link_id: &'a str,
21        page_token: Option<String>,
22        q: Option<String>,
23    ) -> Result<crate::types::ListLinkConversationsResponse, crate::types::error::Error> {
24        let mut req = self.client.client.request(
25            http::Method::GET,
26            &format!(
27                "{}/{}",
28                self.client.base_url,
29                "links/{link_id}/conversations".replace("{link_id}", link_id)
30            ),
31        );
32        req = req.bearer_auth(&self.client.token);
33        let mut query_params = Vec::new();
34        if let Some(p) = limit {
35            query_params.push(("limit", format!("{}", p)));
36        }
37
38        if let Some(p) = page_token {
39            query_params.push(("page_token", p));
40        }
41
42        if let Some(p) = q {
43            query_params.push(("q", p));
44        }
45
46        req = req.query(&query_params);
47        let resp = req.send().await?;
48        let status = resp.status();
49        if status.is_success() {
50            let text = resp.text().await.unwrap_or_default();
51            serde_json::from_str(&text).map_err(|err| {
52                crate::types::error::Error::from_serde_error(
53                    format_serde_error::SerdeError::new(text.to_string(), err),
54                    status,
55                )
56            })
57        } else {
58            Err(crate::types::error::Error::UnexpectedResponse(resp))
59        }
60    }
61
62    #[doc = "List links\n\nList the links of the company paginated by id. Allows filtering by link type via the q.types param.\n\n**Parameters:**\n\n- `limit: Option<i64>`: Max number of results per page\n- `page_token: Option<String>`: Token to use to request the next page\n- `q: Option<String>`: Search query object with a property `types`, whose value should be a list of link types (examples - `web`, `jira`, `asana` ).\n\n```rust,no_run\nasync fn example_links_list() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::ListLinksResponse = client\n        .links()\n        .list(\n            Some(4 as i64),\n            Some(\"some-string\".to_string()),\n            Some(\"some-string\".to_string()),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
63    #[tracing::instrument]
64    pub async fn list<'a>(
65        &'a self,
66        limit: Option<i64>,
67        page_token: Option<String>,
68        q: Option<String>,
69    ) -> Result<crate::types::ListLinksResponse, crate::types::error::Error> {
70        let mut req = self.client.client.request(
71            http::Method::GET,
72            &format!("{}/{}", self.client.base_url, "links"),
73        );
74        req = req.bearer_auth(&self.client.token);
75        let mut query_params = Vec::new();
76        if let Some(p) = limit {
77            query_params.push(("limit", format!("{}", p)));
78        }
79
80        if let Some(p) = page_token {
81            query_params.push(("page_token", p));
82        }
83
84        if let Some(p) = q {
85            query_params.push(("q", p));
86        }
87
88        req = req.query(&query_params);
89        let resp = req.send().await?;
90        let status = resp.status();
91        if status.is_success() {
92            let text = resp.text().await.unwrap_or_default();
93            serde_json::from_str(&text).map_err(|err| {
94                crate::types::error::Error::from_serde_error(
95                    format_serde_error::SerdeError::new(text.to_string(), err),
96                    status,
97                )
98            })
99        } else {
100            Err(crate::types::error::Error::UnexpectedResponse(resp))
101        }
102    }
103
104    #[doc = "Create link\n\nCreate a link. If the link is resolved to an installed links \
105             integration, any name retrieved from the integration will override the provided \
106             name.\n\n```rust,no_run\nasync fn example_links_create() -> anyhow::Result<()> {\n    \
107             let client = front_api::Client::new_from_env();\n    let result: \
108             front_api::types::LinkResponse = client\n        .links()\n        \
109             .create(&front_api::types::CreateLink {\n            name: \
110             Some(\"some-string\".to_string()),\n            external_url: \
111             \"some-string\".to_string(),\n        })\n        .await?;\n    println!(\"{:?}\", \
112             result);\n    Ok(())\n}\n```"]
113    #[tracing::instrument]
114    pub async fn create<'a>(
115        &'a self,
116        body: &crate::types::CreateLink,
117    ) -> Result<crate::types::LinkResponse, crate::types::error::Error> {
118        let mut req = self.client.client.request(
119            http::Method::POST,
120            &format!("{}/{}", self.client.base_url, "links"),
121        );
122        req = req.bearer_auth(&self.client.token);
123        req = req.json(body);
124        let resp = req.send().await?;
125        let status = resp.status();
126        if status.is_success() {
127            let text = resp.text().await.unwrap_or_default();
128            serde_json::from_str(&text).map_err(|err| {
129                crate::types::error::Error::from_serde_error(
130                    format_serde_error::SerdeError::new(text.to_string(), err),
131                    status,
132                )
133            })
134        } else {
135            Err(crate::types::error::Error::UnexpectedResponse(resp))
136        }
137    }
138
139    #[doc = "Get link\n\nFetch a link.\n\n**Parameters:**\n\n- `link_id: &'astr`: The link ID (required)\n\n```rust,no_run\nasync fn example_links_get() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::LinkResponse = client.links().get(\"some-string\").await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
140    #[tracing::instrument]
141    pub async fn get<'a>(
142        &'a self,
143        link_id: &'a str,
144    ) -> Result<crate::types::LinkResponse, crate::types::error::Error> {
145        let mut req = self.client.client.request(
146            http::Method::GET,
147            &format!(
148                "{}/{}",
149                self.client.base_url,
150                "links/{link_id}".replace("{link_id}", link_id)
151            ),
152        );
153        req = req.bearer_auth(&self.client.token);
154        let resp = req.send().await?;
155        let status = resp.status();
156        if status.is_success() {
157            let text = resp.text().await.unwrap_or_default();
158            serde_json::from_str(&text).map_err(|err| {
159                crate::types::error::Error::from_serde_error(
160                    format_serde_error::SerdeError::new(text.to_string(), err),
161                    status,
162                )
163            })
164        } else {
165            Err(crate::types::error::Error::UnexpectedResponse(resp))
166        }
167    }
168
169    #[doc = "Update a link\n\nUpdate a link.\n\n**Parameters:**\n\n- `link_id: &'astr`: The link \
170             ID (required)\n\n```rust,no_run\nasync fn example_links_update() -> \
171             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    \
172             client\n        .links()\n        .update(\n            \"some-string\",\n            \
173             &serde_json::Value::String(\"some-string\".to_string()),\n        )\n        \
174             .await?;\n    Ok(())\n}\n```"]
175    #[tracing::instrument]
176    pub async fn update<'a>(
177        &'a self,
178        link_id: &'a str,
179        body: &crate::types::UpdateLink,
180    ) -> Result<(), crate::types::error::Error> {
181        let mut req = self.client.client.request(
182            http::Method::PATCH,
183            &format!(
184                "{}/{}",
185                self.client.base_url,
186                "links/{link_id}".replace("{link_id}", link_id)
187            ),
188        );
189        req = req.bearer_auth(&self.client.token);
190        req = req.json(body);
191        let resp = req.send().await?;
192        let status = resp.status();
193        if status.is_success() {
194            Ok(())
195        } else {
196            Err(crate::types::error::Error::UnexpectedResponse(resp))
197        }
198    }
199}