aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jake Swenson <jakeswenson@users.noreply.github.com> 2021-05-23 10:31:38 -0700
committerGravatar GitHub <noreply@github.com> 2021-05-23 10:31:38 -0700
commit9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac (patch)
tree735b1031148d4cddfa1a0e01f52b02e23e94f9cb /src
parent4cffa16633f83b6604f7ce3de47d40a29e6a9b54 (diff)
downloadnotion-9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac.tar.gz
notion-9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac.tar.zst
notion-9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac.zip
Add initial todo example (#13)
Diffstat (limited to 'src')
-rw-r--r--src/models.rs28
-rw-r--r--src/models/search.rs9
-rw-r--r--src/models/text.rs11
3 files changed, 48 insertions, 0 deletions
diff --git a/src/models.rs b/src/models.rs
index 82ef7c9..78ad105 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -66,6 +66,15 @@ impl AsIdentifier<DatabaseId> for Database {
}
}
+impl Database {
+ pub fn title_plain_text(&self) -> String {
+ self.title
+ .iter()
+ .flat_map(|rich_text| rich_text.plain_text().chars())
+ .collect()
+ }
+}
+
/// https://developers.notion.com/reference/pagination#responses
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
pub struct ListResponse<T> {
@@ -80,6 +89,25 @@ impl<T> ListResponse<T> {
}
}
+impl ListResponse<Object> {
+ pub fn only_databases(self) -> ListResponse<Database> {
+ let databases = self
+ .results
+ .into_iter()
+ .filter_map(|object| match object {
+ Object::Database { database } => Some(database),
+ _ => None,
+ })
+ .collect();
+
+ ListResponse {
+ results: databases,
+ has_more: self.has_more,
+ next_cursor: self.next_cursor,
+ }
+ }
+}
+
/// A zero-cost wrapper type around a Page ID
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
#[serde(transparent)]
diff --git a/src/models/search.rs b/src/models/search.rs
index 6de3c8a..ffcac1d 100644
--- a/src/models/search.rs
+++ b/src/models/search.rs
@@ -310,6 +310,15 @@ pub enum NotionSearch {
},
}
+impl NotionSearch {
+ pub fn filter_by_databases() -> Self {
+ Self::Filter {
+ property: FilterProperty::Object,
+ value: FilterValue::Database,
+ }
+ }
+}
+
impl From<NotionSearch> for SearchRequest {
fn from(search: NotionSearch) -> Self {
match search {
diff --git a/src/models/text.rs b/src/models/text.rs
index a10007d..f7ea2b6 100644
--- a/src/models/text.rs
+++ b/src/models/text.rs
@@ -81,3 +81,14 @@ pub enum RichText {
rich_text: RichTextCommon,
},
}
+
+impl RichText {
+ pub fn plain_text(&self) -> &str {
+ use RichText::*;
+ match self {
+ Text { rich_text, .. } | Mention { rich_text, .. } | Equation { rich_text, .. } => {
+ &rich_text.plain_text
+ }
+ }
+ }
+}