aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs25
-rw-r--r--src/models.rs88
2 files changed, 66 insertions, 47 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5d9919a..637dda2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -111,7 +111,7 @@ impl NotionApi {
Ok(NotionApi::make_json_request(
self.client.get(&format!(
"https://api.notion.com/v1/blocks/{block_id}/children",
- block_id = block_id.id().id()
+ block_id = block_id.id()
))
).await?)
}
@@ -123,8 +123,8 @@ mod tests {
use crate::models::search::{
DatabaseQuery, FilterCondition, FilterProperty, FilterValue, NotionSearch, TextCondition,
};
- use crate::models::Object;
- use crate::NotionApi;
+ use crate::models::{Object, BlockId};
+ use crate::{NotionApi, Identifiable};
fn test_token() -> String {
let token = {
@@ -225,19 +225,14 @@ mod tests {
})
.await?;
- for page in search_response.results() {
- let response = api
- .get_block_children(page)
- .await?;
- }
-
+ println!("{:?}", search_response.results.len());
- // let db = response.results()[0].clone();
- //
- // // todo: fix this clone issue
- // let db_result = api.get_database(db.clone()).await?;
- //
- // assert_eq!(db, db_result);
+ for object in search_response.results {
+ let _block = match object {
+ Object::Page { page } => api.get_block_children(BlockId::from(page.id())).await.unwrap(),
+ _ => panic!("Should not have received anything but pages!")
+ };
+ }
Ok(())
}
diff --git a/src/models.rs b/src/models.rs
index cb29e00..9f2cd14 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -135,38 +135,6 @@ pub struct Page {
parent: Parent,
}
-impl Identifiable for String {
- type Type = String;
-
- fn id(&self) -> &Self::Type {
- self
- }
-}
-
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
-#[serde(transparent)]
-pub struct BlockId(String);
-
-impl BlockId {
- pub fn id(&self) -> &str {
- &self.0
- }
-}
-
-impl Identifiable for BlockId {
- type Type = BlockId;
-
- fn id(&self) -> &Self::Type {
- self
- }
-}
-
-impl Display for BlockId {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- self.0.fmt(f)
- }
-}
-
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(rename_all = "snake_case")]
pub enum BlockType {
@@ -268,6 +236,34 @@ pub enum Block {
Unsupported {}
}
+impl Identifiable for Block {
+ type Type = BlockId;
+
+ fn id(&self) -> &Self::Type {
+ match self {
+ Block::Paragraph { common, paragraph: _ } => &common.id,
+ Block::Heading1 { common, heading_1: _} => &common.id,
+ Block::Heading2 { common, heading_2: _} => &common.id,
+ Block::Heading3 { common, heading_3: _} => &common.id,
+ Block::BulletedListItem { common, bulleted_list_item: _} => &common.id,
+ Block::NumberedListItem { common, numbered_list_item: _} => &common.id,
+ Block::ToDo { common, to_do: _ } => &common.id,
+ Block::Toggle { common, toggle: _} => &common.id,
+ Block::ChildPage { common, child_page: _} => &common.id,
+ Block::Unsupported {} => { panic!("Trying to reference identifier for unsupported block!") }
+ }
+
+ }
+}
+
+impl Identifiable for Page {
+ type Type = PageId;
+
+ fn id(&self) -> &Self::Type {
+ &self.id
+ }
+}
+
#[derive(Eq, Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(tag = "object")]
#[serde(rename_all = "snake_case")]
@@ -294,6 +290,34 @@ pub enum Object {
},
}
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
+#[serde(transparent)]
+pub struct BlockId(String);
+
+impl BlockId {
+ pub fn id(&self) -> &str {
+ &self.0
+ }
+
+ pub fn from(page_id: &PageId) -> Self {
+ BlockId(page_id.clone().0)
+ }
+}
+
+impl Identifiable for BlockId {
+ type Type = BlockId;
+
+ fn id(&self) -> &Self::Type {
+ self
+ }
+}
+
+impl Display for BlockId {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ self.0.fmt(f)
+ }
+}
+
impl Object {
pub fn is_database(&self) -> bool {
matches!(self, Object::Database { .. })
rt'>fork/markdoc-poc-with-md-support Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/packages/astro/test/fixtures/component-library (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2024-02-27Improve the message of `MiddlewareCantBeLoaded` for clarity (#10239)Gravatar Ming-jun Lu 2-1/+6
2024-02-26[ci] formatGravatar Martin Trapp 1-1/+3
2024-02-26Warn when view transitions run on a prefer-reduced-motion device (#10222)Gravatar Martin Trapp 2-0/+8
2024-02-26[ci] release (#10218)astro@4.4.5@astrojs/vercel@7.3.4@astrojs/svelte@5.1.0@astrojs/db@0.4.1Gravatar Houston (Bot) 46-114/+100
2024-02-26fix: better assetsInlineLimit runtime type checking (#10154)Gravatar James Ross 2-9/+13
2024-02-26fix: correct remote url (#10223)Gravatar Ben Holmes 2-2/+8
2024-02-26fix(toolbar): Make it so every built-in app can be closed by outside clicks (...Gravatar Erika 8-51/+63
2024-02-26Fix an issue where Vercel adapter may create functions for prerendered routes...Gravatar Ming-jun Lu 4-2/+26
2024-02-26[ci] formatGravatar Matthew Phillips 1-1/+1
2024-02-26Fix hydration scripts missing from dynamic slot usage (#10219)Gravatar Matthew Phillips 6-1/+69
2024-02-26[ci] formatGravatar Matthew Phillips 1-5/+5
2024-02-26Prevent errors in rendering from crashing server (#10221)Gravatar Matthew Phillips 7-14/+78
2024-02-26fix: svelte 5 mount/hydrate api change. (#10224)Gravatar 前端子鱼 3-5/+12
2024-02-24[ci] formatGravatar Arsh 1-9/+30
2024-02-24prevent warning: `Astro.request.headers` is not available in "static" output ...Gravatar Arsh 2-27/+30
2024-02-23Improved error logging from config (#10207)Gravatar Ben Holmes 4-36/+67
2024-02-23[ci] formatGravatar Arsh 3-3/+3
2024-02-23fix(dev): remove params for prerendered pages (#10199)Gravatar Arsh 9-13/+78
2024-02-23[ci] release (#10213)astro@4.4.4@astrojs/vercel@7.3.3@astrojs/node@8.2.1@astrojs/db@0.4.0Gravatar Houston (Bot) 41-177/+95
2024-02-23Fixes edge middleware calling nested routes (#10215)Gravatar Matthew Phillips 2-1/+6
2024-02-23Adds an error message for non-string transition:name values (#10205)Gravatar Martin Trapp 2-0/+8
2024-02-23[ci] formatGravatar Furkan Erdem 1-1/+1
2024-02-23Fix(node): Custom headers are not present in responses from standalone Node s...Gravatar Furkan Erdem 8-0/+163