diff options
author | 2021-05-16 07:54:31 -0700 | |
---|---|---|
committer | 2021-05-16 22:17:54 -0700 | |
commit | 2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908 (patch) | |
tree | 1d16229bad209fa9acbcbfc595672999df6d688e | |
parent | e1005f715bde3fb260d97a1a08e3e1de358471d6 (diff) | |
download | notion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.tar.gz notion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.tar.zst notion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.zip |
generic block
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/models.rs | 24 |
2 files changed, 24 insertions, 4 deletions
@@ -104,14 +104,14 @@ impl NotionApi { .await?) } - pub async fn get_block_children<T: Identifiable>( + pub async fn get_block_children<T: Identifiable<Type = String>>( &self, block_id: T ) -> Result<ListResponse<Block>, NotionApiClientError> { Ok(NotionApi::make_json_request( self.client.get(&format!( "https://api.notion.com/v1/blocks/{block_id}/children", - block_id = block_id.id(). + block_id = block_id.id().id() )) ).await?) } diff --git a/src/models.rs b/src/models.rs index ba98094..142a6da 100644 --- a/src/models.rs +++ b/src/models.rs @@ -168,17 +168,38 @@ impl Display for BlockId { } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum BlockType { + Paragraph, + Heading1, + Heading2, + Heading3, + BulletedListItem, + NumberedListItem, + ToDo, + Toggle, + ChildPage, + Unsupported +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct Block { id: BlockId, + r#type: BlockType, created_time: DateTime<Utc>, last_edited_time: DateTime<Utc>, has_children: bool, } -#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] + +#[derive(Eq, Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(tag = "object")] #[serde(rename_all = "snake_case")] pub enum Object { + Block { + #[serde(flatten)] + block: Block + }, Database { #[serde(flatten)] database: Database, @@ -195,7 +216,6 @@ pub enum Object { #[serde(flatten)] user: User, }, - Block {}, } impl Object { |