notion_client/endpoints/databases/
retrieve.rs1use crate::{
2 endpoints::NOTION_URI,
3 objects::{database::Database, Response},
4 NotionClientError,
5};
6
7use super::DatabasesEndpoint;
8
9impl DatabasesEndpoint {
10 pub async fn retrieve_a_database(
11 &self,
12 database_id: &str,
13 ) -> Result<Database, NotionClientError> {
14 let result = self
15 .client
16 .get(format!(
17 "{notion_uri}/databases/{database_id}",
18 notion_uri = NOTION_URI,
19 database_id = database_id
20 ))
21 .send()
22 .await
23 .map_err(|e| NotionClientError::FailedToRequest { source: e })?;
24
25 let body = result
26 .text()
27 .await
28 .map_err(|e| NotionClientError::FailedToText { source: e })?;
29
30 let response = serde_json::from_str(&body)
31 .map_err(|e| NotionClientError::FailedToDeserialize { source: e, body })?;
32
33 match response {
34 Response::Success(r) => Ok(r),
35 Response::Error(e) => Err(NotionClientError::InvalidStatusCode { error: e }),
36 }
37 }
38}