aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Brett Spradling <bspradling@godaddy.com> 2021-05-16 07:54:31 -0700
committerGravatar Brett Spradling <bspradling@godaddy.com> 2021-05-16 22:17:54 -0700
commit2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908 (patch)
tree1d16229bad209fa9acbcbfc595672999df6d688e
parente1005f715bde3fb260d97a1a08e3e1de358471d6 (diff)
downloadnotion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.tar.gz
notion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.tar.zst
notion-2abfa7ef1e5ec11de44ec2c59fb0f0980c6e4908.zip
generic block
-rw-r--r--src/lib.rs4
-rw-r--r--src/models.rs24
2 files changed, 24 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0193a2e..0f9068f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 {