notion_client/endpoints/blocks/
update.rs

1pub mod request;
2
3use crate::{endpoints::NOTION_URI, objects::Response, NotionClientError};
4
5use self::request::UpdateABlockRequest;
6
7use super::BlocksEndpoint;
8
9impl BlocksEndpoint {
10    pub async fn update_a_block(
11        &self,
12        block_id: &str,
13        request: UpdateABlockRequest,
14    ) -> Result<UpdateABlockRequest, NotionClientError> {
15        let json = serde_json::to_string(&request)
16            .map_err(|e| NotionClientError::FailedToSerialize { source: e })?;
17
18        let result = self
19            .client
20            .patch(format!(
21                "{notion_uri}/blocks/{block_id}",
22                notion_uri = NOTION_URI,
23                block_id = block_id
24            ))
25            .body(json)
26            .send()
27            .await
28            .map_err(|e| NotionClientError::FailedToRequest { source: e })?;
29
30        let body = result
31            .text()
32            .await
33            .map_err(|e| NotionClientError::FailedToText { source: e })?;
34
35        let response = serde_json::from_str(&body)
36            .map_err(|e| NotionClientError::FailedToDeserialize { source: e, body })?;
37
38        match response {
39            Response::Success(r) => Ok(r),
40            Response::Error(e) => Err(NotionClientError::InvalidStatusCode { error: e }),
41        }
42    }
43}