From e1005f715bde3fb260d97a1a08e3e1de358471d6 Mon Sep 17 00:00:00 2001 From: Brett Spradling Date: Sat, 15 May 2021 23:55:19 -0700 Subject: wip --- src/lib.rs | 16 ++++++++++++++-- src/models.rs | 39 ++++++++++++++++++++++++++++++++++++++- src/models/properties.rs | 2 +- 3 files changed, 53 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index c97ee48..0193a2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,10 @@ use crate::models::search::{DatabaseQuery, SearchRequest}; -use crate::models::{Database, DatabaseId, ListResponse, Object, Page}; +use crate::models::{Database, DatabaseId, ListResponse, Object, Page, Block}; use reqwest::header::{HeaderMap, HeaderValue}; use reqwest::{header, Client, ClientBuilder, RequestBuilder}; use serde::de::DeserializeOwned; -mod models; +pub mod models; const NOTION_API_VERSION: &'static str = "2021-05-13"; @@ -103,6 +103,18 @@ impl NotionApi { ) .await?) } + + pub async fn get_block_children( + &self, + block_id: T + ) -> Result, NotionApiClientError> { + Ok(NotionApi::make_json_request( + self.client.get(&format!( + "https://api.notion.com/v1/blocks/{block_id}/children", + block_id = block_id.id(). + )) + ).await?) + } } #[cfg(test)] diff --git a/src/models.rs b/src/models.rs index f0909d9..ba98094 100644 --- a/src/models.rs +++ b/src/models.rs @@ -135,8 +135,45 @@ pub struct Page { parent: Parent, } +impl Identifiable for String { + type Type = String; + + fn id(&self) -> &Self::Type { + self + } +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)] +#[serde(transparent)] +pub struct BlockId(String); + +impl BlockId { + pub fn id(&self) -> &str { + &self.0 + } +} + +impl Identifiable for BlockId { + type Type = BlockId; + + fn id(&self) -> &Self::Type { + self + } +} + +impl Display for BlockId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] -pub struct Block {} +pub struct Block { + id: BlockId, + created_time: DateTime, + last_edited_time: DateTime, + has_children: bool, +} #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] #[serde(tag = "object")] diff --git a/src/models/properties.rs b/src/models/properties.rs index c55ce1a..44f723b 100644 --- a/src/models/properties.rs +++ b/src/models/properties.rs @@ -157,7 +157,7 @@ pub enum PropertyConfiguration { Checkbox { id: PropertyId }, /// Represents a URL Property /// See https://developers.notion.com/reference/database#url-configuration - URL { id: PropertyId }, + Url { id: PropertyId }, /// Represents a Email Property /// See https://developers.notion.com/reference/database#email-configuration Email { id: PropertyId }, -- cgit v1.2.3