diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ids.rs | 10 | ||||
-rw-r--r-- | src/lib.rs | 17 | ||||
-rw-r--r-- | src/models/properties.rs | 4 |
3 files changed, 28 insertions, 3 deletions
@@ -1,9 +1,9 @@ use std::fmt::Display; +use std::fmt::Error; pub trait Identifier: Display { fn value(&self) -> &str; } - /// Meant to be a helpful trait allowing anything that can be /// identified by the type specified in `ById`. pub trait AsIdentifier<ById: Identifier> { @@ -45,6 +45,14 @@ macro_rules! identifer { self.0.fmt(f) } } + + impl std::str::FromStr for $name { + type Err = Error; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok($name(s.to_string())) + } + } }; } @@ -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, diff --git a/src/models/properties.rs b/src/models/properties.rs index b46b7f7..f7e3897 100644 --- a/src/models/properties.rs +++ b/src/models/properties.rs @@ -103,6 +103,7 @@ pub enum RollupFunction { Min, Max, Range, + ShowOriginal, } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] @@ -284,9 +285,10 @@ pub enum PropertyValue { formula: FormulaResultValue, }, /// <https://developers.notion.com/reference/page#relation-property-values> + /// It is actually an array of relations Relation { id: PropertyId, - relation: RelationValue, + relation: Option<Vec<RelationValue>>, }, Rollup { id: PropertyId, |