Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod database;
pub mod emoji;
pub mod error;
pub mod file;
pub mod native_icon;
pub mod page;
pub mod parent;
pub mod property;
Expand Down
6 changes: 5 additions & 1 deletion src/objects/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User};
use super::{
emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, rich_text::RichText,
user::User,
};

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
Expand Down Expand Up @@ -341,6 +344,7 @@ pub enum TextColor {
pub enum Icon {
File(File),
Emoji(Emoji),
NativeIcon(NativeIcon),
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
Expand Down
5 changes: 3 additions & 2 deletions src/objects/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

use super::{
database::DatabaseProperty, emoji::Emoji, file::File, parent::Parent, rich_text::RichText,
user::User,
database::DatabaseProperty, emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent,
rich_text::RichText, user::User,
};

#[skip_serializing_none]
Expand Down Expand Up @@ -37,4 +37,5 @@ pub enum Icon {
None,
File(File),
Emoji(Emoji),
NativeIcon(NativeIcon),
}
6 changes: 5 additions & 1 deletion src/objects/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User};
use super::{
emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, rich_text::RichText,
user::User,
};

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -33,6 +36,7 @@ pub enum Icon {
None,
File(File),
Emoji(Emoji),
NativeIcon(NativeIcon),
}

#[skip_serializing_none]
Expand Down
14 changes: 14 additions & 0 deletions src/objects/native_icon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
#[serde(tag = "type", rename = "icon", rename_all = "snake_case")]
pub enum NativeIcon {
Icon { icon: Native },
}

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub struct Native {
pub name: String,
pub color: Option<String>,
}
5 changes: 3 additions & 2 deletions src/objects/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use serde_with::skip_serializing_none;

use super::{
emoji::Emoji, file::File, parent::Parent, property::DateOrDateTime, rich_text::RichText,
user::User,
emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, property::DateOrDateTime,
rich_text::RichText, user::User,
};

#[skip_serializing_none]
Expand All @@ -32,6 +32,7 @@
pub enum Icon {
File(File),
Emoji(Emoji),
NativeIcon(NativeIcon),
}

#[skip_serializing_none]
Expand Down Expand Up @@ -241,7 +242,7 @@
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct UniqueIDPropertyValue {
#[serde(default)]
#[doc = "This field is null only in extremely rare cases, for instance when it's being used as a Template for a Task in Notion's Project Management Template: https://www.notion.so/templates/notion-projects-and-tasks"]

Check warning on line 245 in src/objects/page.rs

View workflow job for this annotation

GitHub Actions / build

this URL is not a hyperlink
pub number: Option<Number>,
pub prefix: Option<String>,
}
Expand Down
16 changes: 14 additions & 2 deletions src/objects/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::objects::{
block::Block, comment::Comment, emoji::Emoji, error::Error, file::File, page::Page,
rich_text::RichText,
block::Block, comment::Comment, emoji::Emoji, error::Error, file::File,
native_icon::NativeIcon, page::Page, rich_text::RichText,
};

use super::block::CalloutValue;
Expand Down Expand Up @@ -70,3 +70,15 @@ fn test_mention_date_only() {
let result = serde_json::from_str::<RichText>(include_str!("tests/mention_date.json"));
assert!(result.is_ok());
}

#[test]
fn test_page_icon_native() {
let result = serde_json::from_str::<NativeIcon>(include_str!("tests/native_icon.json"));
assert!(result.is_ok());
}

#[test]
fn test_page_icon_native_page() {
let result = serde_json::from_str::<Page>(include_str!("tests/page_native_icon.json"));
assert!(result.is_ok());
}
7 changes: 7 additions & 0 deletions src/objects/tests/native_icon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "icon",
"icon": {
"name": "book-closed",
"color": "lightgray"
}
}
78 changes: 78 additions & 0 deletions src/objects/tests/page_native_icon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"object": "page",
"id": "be633bf1-dfa0-436d-b259-571129a590e5",
"created_time": "2022-10-24T22:54:00.000Z",
"last_edited_time": "2023-03-08T18:25:00.000Z",
"created_by": {
"object": "user",
"id": "c2f20311-9e54-4d11-8c79-7398424ae41e"
},
"last_edited_by": {
"object": "user",
"id": "9188c6a5-7381-452f-b3dc-d4865aa89bdf"
},
"cover": null,
"icon": {
"type": "icon",
"icon": {
"name": "book-closed",
"color": "lightgray"
}
},
"parent": {
"type": "database_id",
"database_id": "a1d8501e-1ac1-43e9-a6bd-ea9fe6c8822b"
},
"in_trash": true,
"properties": {
"Due date": {
"id": "M%3BBw",
"type": "date",
"date": {
"start": "2023-02-23",
"end": null,
"time_zone": null
}
},
"Status": {
"id": "Z%3ClH",
"type": "status",
"status": {
"id": "86ddb6ec-0627-47f8-800d-b65afd28be13",
"name": "Not started",
"color": "default"
}
},
"Title": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "Bug bash",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Bug bash",
"href": null
}
]
},
"Button": {
"id": "KJOc",
"type": "button",
"button": {}
}
},
"url": "https://www.notion.so/Bug-bash-be633bf1dfa0436db259571129a590e5",
"public_url": "https://jm-testing.notion.site/p1-6df2c07bfc6b4c46815ad205d132e22d"
}

Loading