aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Brett Spradling <brett@spradling.me> 2021-05-16 23:40:13 -0700
committerGravatar GitHub <noreply@github.com> 2021-05-16 23:40:13 -0700
commit68819a887e9498c8786baaa6c3f098801b91e354 (patch)
treeacfb6f1c0ba0eb3357afc143b4e8f7c45b298d23 /src/lib.rs
parente498b3c10e4975993352048b502cbcf55193850b (diff)
downloadnotion-68819a887e9498c8786baaa6c3f098801b91e354.tar.gz
notion-68819a887e9498c8786baaa6c3f098801b91e354.tar.zst
notion-68819a887e9498c8786baaa6c3f098801b91e354.zip
Get Children Blocks (#9)
* wip * generic block * refactor * all blocks * format * PR Feedback * more feedback Co-authored-by: Brett Spradling <bspradling@godaddy.com>
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c74aadf..e059a48 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,11 +1,11 @@
use crate::models::search::{DatabaseQuery, SearchRequest};
-use crate::models::{Database, DatabaseId, ListResponse, Object, Page};
+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;
use snafu::{ResultExt, Snafu};
-mod models;
+pub mod models;
const NOTION_API_VERSION: &str = "2021-05-13";
@@ -127,6 +127,17 @@ impl NotionApi {
)
.await?)
}
+
+ pub async fn get_block_children<T: Identifiable<Type = BlockId>>(
+ &self,
+ 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?)
+ }
}
#[cfg(test)]
@@ -135,8 +146,8 @@ mod tests {
use crate::models::search::{
DatabaseQuery, FilterCondition, FilterProperty, FilterValue, NotionSearch, TextCondition,
};
- use crate::models::Object;
- use crate::NotionApi;
+ use crate::models::{BlockId, Object};
+ use crate::{Identifiable, NotionApi};
fn test_token() -> String {
let token = {
@@ -227,6 +238,32 @@ mod tests {
}
#[tokio::test]
+ async fn get_block_children() -> Result<(), Box<dyn std::error::Error>> {
+ let api = test_client();
+
+ let search_response = api
+ .search(NotionSearch::Filter {
+ value: FilterValue::Page,
+ property: FilterProperty::Object,
+ })
+ .await?;
+
+ println!("{:?}", search_response.results.len());
+
+ for object in search_response.results {
+ match object {
+ Object::Page { page } => api
+ .get_block_children(BlockId::from(page.id()))
+ .await
+ .unwrap(),
+ _ => panic!("Should not have received anything but pages!"),
+ };
+ }
+
+ Ok(())
+ }
+
+ #[tokio::test]
async fn query_database() -> Result<(), Box<dyn std::error::Error>> {
let api = test_client();