diff options
author | 2021-05-15 23:55:19 -0700 | |
---|---|---|
committer | 2021-05-16 22:17:54 -0700 | |
commit | e1005f715bde3fb260d97a1a08e3e1de358471d6 (patch) | |
tree | e4d8baeb42d9fd74699aec99c9804aa67571f4db | |
parent | a2dc79a5079d6286ebd148cf25a00e5dd013efdc (diff) | |
download | notion-e1005f715bde3fb260d97a1a08e3e1de358471d6.tar.gz notion-e1005f715bde3fb260d97a1a08e3e1de358471d6.tar.zst notion-e1005f715bde3fb260d97a1a08e3e1de358471d6.zip |
wip
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/models.rs | 39 | ||||
-rw-r--r-- | src/models/properties.rs | 2 |
3 files changed, 53 insertions, 4 deletions
@@ -1,10 +1,10 @@ use crate::models::search::{DatabaseQuery, SearchRequest}; -use crate::models::{Database, DatabaseId, ListResponse, Object, Page}; +use crate::models::{Database, DatabaseId, ListResponse, Object, Page, Block}; use reqwest::header::{HeaderMap, HeaderValue}; use reqwest::{header, Client, ClientBuilder, RequestBuilder}; use serde::de::DeserializeOwned; -mod models; +pub mod models; const NOTION_API_VERSION: &'static str = "2021-05-13"; @@ -103,6 +103,18 @@ impl NotionApi { ) .await?) } + + pub async fn get_block_children<T: Identifiable>( + &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?) + } } #[cfg(test)] diff --git a/src/models.rs b/src/models.rs index f0909d9..ba98094 100644 --- a/src/models.rs +++ b/src/models.rs @@ -135,8 +135,45 @@ 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)] -pub struct Block {} +pub struct Block { + id: BlockId, + created_time: DateTime<Utc>, + last_edited_time: DateTime<Utc>, + has_children: bool, +} #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] #[serde(tag = "object")] diff --git a/src/models/properties.rs b/src/models/properties.rs index c55ce1a..44f723b 100644 --- a/src/models/properties.rs +++ b/src/models/properties.rs @@ -157,7 +157,7 @@ pub enum PropertyConfiguration { Checkbox { id: PropertyId }, /// Represents a URL Property /// See https://developers.notion.com/reference/database#url-configuration - URL { id: PropertyId }, + Url { id: PropertyId }, /// Represents a Email Property /// See https://developers.notion.com/reference/database#email-configuration Email { id: PropertyId }, |