diff options
author | 2021-05-16 22:59:08 -0700 | |
---|---|---|
committer | 2021-05-16 23:04:09 -0700 | |
commit | c33ac6632869048d1b904ef3891fd54ab2cf70f2 (patch) | |
tree | 5419fa9913179537a8c9a8cd67a4555e3b65d3ee /src | |
parent | adf612dc81fbfe347c3dd67ebcfb23eab9dbdff5 (diff) | |
download | notion-feature/block-children.tar.gz notion-feature/block-children.tar.zst notion-feature/block-children.zip |
formatfeature/block-children
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 30 | ||||
-rw-r--r-- | src/models.rs | 56 |
2 files changed, 55 insertions, 31 deletions
@@ -1,5 +1,5 @@ use crate::models::search::{DatabaseQuery, SearchRequest}; -use crate::models::{Database, DatabaseId, ListResponse, Object, Page, Block, BlockId}; +use crate::models::{Block, BlockId, Database, DatabaseId, ListResponse, Object, Page}; use reqwest::header::{HeaderMap, HeaderValue}; use reqwest::{header, Client, ClientBuilder, RequestBuilder}; use serde::de::DeserializeOwned; @@ -130,14 +130,13 @@ impl NotionApi { pub async fn get_block_children<T: Identifiable<Type = BlockId>>( &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() - )) - ).await?) + block_id: T, + ) -> Result<ListResponse<Block>, Error> { + Ok(NotionApi::make_json_request(self.client.get(&format!( + "https://api.notion.com/v1/blocks/{block_id}/children", + block_id = block_id.id() + ))) + .await?) } } @@ -147,8 +146,8 @@ mod tests { use crate::models::search::{ DatabaseQuery, FilterCondition, FilterProperty, FilterValue, NotionSearch, TextCondition, }; - use crate::models::{Object, BlockId}; - use crate::{NotionApi, Identifiable}; + use crate::models::{BlockId, Object}; + use crate::{Identifiable, NotionApi}; fn test_token() -> String { let token = { @@ -252,9 +251,12 @@ mod tests { println!("{:?}", search_response.results.len()); 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!") + match object { + Object::Page { page } => api + .get_block_children(BlockId::from(page.id())) + .await + .unwrap(), + _ => panic!("Should not have received anything but pages!"), }; } diff --git a/src/models.rs b/src/models.rs index 9f2cd14..8f4cd17 100644 --- a/src/models.rs +++ b/src/models.rs @@ -147,7 +147,7 @@ pub enum BlockType { ToDo, Toggle, ChildPage, - Unsupported + Unsupported, } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] @@ -188,21 +188,21 @@ pub enum Block { Paragraph { #[serde(flatten)] common: BlockCommon, - paragraph: TextAndChildren + paragraph: TextAndChildren, }, - #[serde(rename="heading_1")] + #[serde(rename = "heading_1")] Heading1 { #[serde(flatten)] common: BlockCommon, heading_1: Text, }, - #[serde(rename="heading_2")] + #[serde(rename = "heading_2")] Heading2 { #[serde(flatten)] common: BlockCommon, heading_2: Text, }, - #[serde(rename="heading_3")] + #[serde(rename = "heading_3")] Heading3 { #[serde(flatten)] common: BlockCommon, @@ -233,7 +233,7 @@ pub enum Block { common: BlockCommon, child_page: ChildPageFields, }, - Unsupported {} + Unsupported {}, } impl Identifiable for Block { @@ -241,18 +241,40 @@ impl Identifiable for Block { 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::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!") } + Block::Toggle { common, toggle: _ } => &common.id, + Block::ChildPage { + common, + child_page: _, + } => &common.id, + Block::Unsupported {} => { + panic!("Trying to reference identifier for unsupported block!") + } } - } } @@ -270,7 +292,7 @@ impl Identifiable for Page { pub enum Object { Block { #[serde(flatten)] - block: Block + block: Block, }, Database { #[serde(flatten)] |