Skip to content

Commit

Permalink
generic block
Browse files Browse the repository at this point in the history
  • Loading branch information
bspradling-godaddy committed May 16, 2021
1 parent 4db6c7c commit aefe435
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -101,14 +101,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?)
}
Expand Down
22 changes: 21 additions & 1 deletion src/models.rs
Expand Up @@ -165,17 +165,37 @@ 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)]
#[derive(Eq, Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(tag = "object")]
pub enum Object {
Block {
#[serde(flatten)]
block: Block
},
Database {
#[serde(flatten)]
database: Database,
Expand Down

0 comments on commit aefe435

Please sign in to comment.