diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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, |