From 9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac Mon Sep 17 00:00:00 2001 From: Jake Swenson Date: Sun, 23 May 2021 10:31:38 -0700 Subject: Add initial todo example (#13) --- src/models.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/models.rs') 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 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 { @@ -80,6 +89,25 @@ impl ListResponse { } } +impl ListResponse { + pub fn only_databases(self) -> ListResponse { + 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)] -- cgit v1.2.3