aboutsummaryrefslogtreecommitdiff
path: root/src/models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models.rs')
-rw-r--r--src/models.rs28
1 files changed, 28 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)]