aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGravatar ahmetrehaseker <ahmetrehaseker@gmail.com> 2023-01-02 19:19:41 +0300
committerGravatar GitHub <noreply@github.com> 2023-01-02 08:19:41 -0800
commit43fd57ab2f7fd0e478001d97be5e66156feaa4cc (patch)
tree0632240109ec51b32e9480aceb0efb8aac504647 /src/lib.rs
parent1e4f1d49919bf4dd0cfe1af1fcd95d1d90e4b7ff (diff)
downloadnotion-43fd57ab2f7fd0e478001d97be5e66156feaa4cc.tar.gz
notion-43fd57ab2f7fd0e478001d97be5e66156feaa4cc.tar.zst
notion-43fd57ab2f7fd0e478001d97be5e66156feaa4cc.zip
Add create page functionality (#44)
* Change text to rich_text * Add craete page functionality Co-authored-by: Jake Swenson <jakeswenson@users.noreply.github.com>
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2b9711b..46c3358 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,6 +3,7 @@ use crate::models::error::ErrorResponse;
use crate::models::search::{DatabaseQuery, SearchRequest};
use crate::models::{Block, Database, ListResponse, Object, Page};
use ids::{AsIdentifier, PageId};
+use models::PageCreateRequest;
use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::{header, Client, ClientBuilder, RequestBuilder};
use tracing::Instrument;
@@ -178,6 +179,22 @@ impl NotionApi {
}
}
+ /// Creates a new page and return the created page
+ pub async fn create_page<T: Into<PageCreateRequest>>(&self, page: T) -> Result<Page, Error> {
+ let result = self
+ .make_json_request(
+ self.client
+ .post("https://api.notion.com/v1/pages")
+ .json(&page.into()),
+ )
+ .await?;
+
+ match result {
+ Object::Page { page } => Ok(page),
+ response => Err(Error::UnexpectedResponse { response }),
+ }
+ }
+
/// Query a database and return the matching pages.
pub async fn query_database<D, T>(
&self,