aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Gavrovsky <dmitrygavrovsky@gmail.com> 2021-12-11 20:23:11 +0200
committerGravatar GitHub <noreply@github.com> 2021-12-11 10:23:11 -0800
commitf48378ec16af1035af32ed16592099104a552d90 (patch)
tree5407e21cb7e99d379c5c6f5474def43ad7e99388 /src
parente28f581e1d91bbe40074c47a90b0bdf6528107c2 (diff)
downloadnotion-f48378ec16af1035af32ed16592099104a552d90.tar.gz
notion-f48378ec16af1035af32ed16592099104a552d90.tar.zst
notion-f48378ec16af1035af32ed16592099104a552d90.zip
fix(example): Example wasn't compling + lib fixes (#19)
* get page + query database bugfixes * fixed wrong error type * clap integration fix * comments cleaning * source formatting using cargo format
Diffstat (limited to 'src')
-rw-r--r--src/ids.rs10
-rw-r--r--src/lib.rs17
-rw-r--r--src/models/properties.rs4
3 files changed, 28 insertions, 3 deletions
diff --git a/src/ids.rs b/src/ids.rs
index 2ede5e0..beffd06 100644
--- a/src/ids.rs
+++ b/src/ids.rs
@@ -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()))
+ }
+ }
};
}
diff --git a/src/lib.rs b/src/lib.rs
index 98ea97f..ac45a35 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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,