diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -2,7 +2,7 @@ use crate::ids::{BlockId, DatabaseId}; use crate::models::error::ErrorResponse; use crate::models::search::{DatabaseQuery, SearchRequest}; use crate::models::{Block, Database, ListResponse, Object, Page}; -use ids::AsIdentifier; +use ids::{AsIdentifier, PageId}; use reqwest::header::{HeaderMap, HeaderValue}; use reqwest::{header, Client, ClientBuilder, RequestBuilder}; use tracing::Instrument; @@ -161,6 +161,21 @@ impl NotionApi { } } + /// Get a page by [PageId]. + pub async fn get_page<T: AsIdentifier<PageId>>(&self, page_id: T) -> Result<Page, Error> { + let result = self + .make_json_request(self.client.get(format!( + "https://api.notion.com/v1/pages/{}", + page_id.as_id() + ))) + .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, |