aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs30
-rw-r--r--src/models.rs56
2 files changed, 55 insertions, 31 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7c6520f..e059a48 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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)]