From 8160fea0ffa1f074538ec5fd73b317bc9d023d6e Mon Sep 17 00:00:00 2001 From: Shashank Pachava Date: Wed, 18 May 2022 01:02:56 -0400 Subject: Upgrade notion version (#39) * Upgrade constant * Fix lint * Change module file tree Changed around module file tree, but module structure hasn't changed. Converted models.rs to mod.rs under models folder * Minor refactoring * Add MentionObject for rich text mention types * Add new fields to BlockCommon. Modify existing field model Text. Add heading 1 test Add created_by and last_edited_by fields to BlockCommon. Change field text to rich_text for model Text to handle breaking change in API version 2022-02-22 * Differentiate between unsupported and unknown block types * Change text field to rich_text in paragraph block * Add callout block. Add file and emoji object * Fix as_id for unsupported block * Fix lint issues * Move quote block to follow documentation order. Add color field to TextAndChildren struct * Add color field to ToDoFields struct * Formatting * Add caption field to code block Add caption field to code block. Create enum CodeLanguage for code block. Reorder code block to reflect documentation * Add child database block * Create embed block * Refactor notion file object struct name * Create image block * Create video block * Create file block * Fix video block field * Create pdf block * Change text field to rich_text in TodoFields for Notion API version 2022-02-22 * Create bookmark block * Create divider block * Create table of contents block * Create breadcrumb block * Create column list and column block * Create link preview block * Create template block * Formatting * Create link to page block * Fix ColumnListFields struct * Create table and table row block * Fix AsIdentifier trait impl for Block * Create synced block --- src/models/text.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/models/text.rs') diff --git a/src/models/text.rs b/src/models/text.rs index 16274ab..4169374 100644 --- a/src/models/text.rs +++ b/src/models/text.rs @@ -1,4 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::models::users::User; +use crate::{Database, Page}; +use crate::models::properties::DateValue; #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "snake_case")] @@ -56,6 +59,33 @@ pub struct Text { pub link: Option, } +/// See https://developers.notion.com/reference/rich-text#mention-objects +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum MentionObject { + User { + user: User + }, + // TODO: need to add tests + Page { + page: Page + }, + // TODO: need to add tests + Database { + database: Database + }, + Date { + date: DateValue + }, + // TODO: need to add LinkPreview + // LinkPreview { + // + // }, + #[serde(other)] + Unknown +} + /// Rich text objects contain data for displaying formatted text, mentions, and equations. /// A rich text object also contains annotations for style information. /// Arrays of rich text objects are used within property objects and property @@ -74,6 +104,7 @@ pub enum RichText { Mention { #[serde(flatten)] rich_text: RichTextCommon, + mention: MentionObject }, /// See Equation { -- cgit v1.2.3