front_api/
contact_notes.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct ContactNotes {
6    pub client: Client,
7}
8
9impl ContactNotes {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List notes\n\nList the notes added to a contact.\n\n**Parameters:**\n\n- `contact_id: \
16             &'astr`: The contact ID (required)\n\n```rust,no_run\nasync fn \
17             example_contact_notes_list_notes() -> anyhow::Result<()> {\n    let client = \
18             front_api::Client::new_from_env();\n    let result: \
19             front_api::types::ListNotesResponse =\n        \
20             client.contact_notes().list_notes(\"some-string\").await?;\n    println!(\"{:?}\", \
21             result);\n    Ok(())\n}\n```"]
22    #[tracing::instrument]
23    pub async fn list_notes<'a>(
24        &'a self,
25        contact_id: &'a str,
26    ) -> Result<crate::types::ListNotesResponse, crate::types::error::Error> {
27        let mut req = self.client.client.request(
28            http::Method::GET,
29            &format!(
30                "{}/{}",
31                self.client.base_url,
32                "contacts/{contact_id}/notes".replace("{contact_id}", contact_id)
33            ),
34        );
35        req = req.bearer_auth(&self.client.token);
36        let resp = req.send().await?;
37        let status = resp.status();
38        if status.is_success() {
39            let text = resp.text().await.unwrap_or_default();
40            serde_json::from_str(&text).map_err(|err| {
41                crate::types::error::Error::from_serde_error(
42                    format_serde_error::SerdeError::new(text.to_string(), err),
43                    status,
44                )
45            })
46        } else {
47            Err(crate::types::error::Error::UnexpectedResponse(resp))
48        }
49    }
50
51    #[doc = "Add note\n\nCreate a new note on a contact.\n\n**Parameters:**\n\n- `contact_id: &'astr`: The contact ID (required)\n\n```rust,no_run\nasync fn example_contact_notes_add_note() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::ContactNoteResponses = client\n        .contact_notes()\n        .add_note(\n            \"some-string\",\n            &front_api::types::CreateContactNote {\n                author_id: \"some-string\".to_string(),\n                body: \"some-string\".to_string(),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
52    #[tracing::instrument]
53    pub async fn add_note<'a>(
54        &'a self,
55        contact_id: &'a str,
56        body: &crate::types::CreateContactNote,
57    ) -> Result<crate::types::ContactNoteResponses, crate::types::error::Error> {
58        let mut req = self.client.client.request(
59            http::Method::POST,
60            &format!(
61                "{}/{}",
62                self.client.base_url,
63                "contacts/{contact_id}/notes".replace("{contact_id}", contact_id)
64            ),
65        );
66        req = req.bearer_auth(&self.client.token);
67        req = req.json(body);
68        let resp = req.send().await?;
69        let status = resp.status();
70        if status.is_success() {
71            let text = resp.text().await.unwrap_or_default();
72            serde_json::from_str(&text).map_err(|err| {
73                crate::types::error::Error::from_serde_error(
74                    format_serde_error::SerdeError::new(text.to_string(), err),
75                    status,
76                )
77            })
78        } else {
79            Err(crate::types::error::Error::UnexpectedResponse(resp))
80        }
81    }
82}