From c0fa6db0cba1e2176f2e6ebf7f32bfbc2c8b248b Mon Sep 17 00:00:00 2001 From: lifegpc Date: Wed, 6 Jul 2022 13:40:02 +0000 Subject: [PATCH] Update --- src/fanbox/item_list.rs | 2 + src/fanbox/paginated_creator_posts.rs | 2 + src/fanbox/post.rs | 65 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/fanbox/item_list.rs b/src/fanbox/item_list.rs index 758547b..fa67de1 100644 --- a/src/fanbox/item_list.rs +++ b/src/fanbox/item_list.rs @@ -17,6 +17,7 @@ pub struct FanboxItemList { } impl FanboxItemList { + #[allow(dead_code)] /// Get next page. /// # Note /// If no next page presented, will return a error. @@ -38,6 +39,7 @@ impl FanboxItemList { } } + #[allow(dead_code)] /// Returns true if next page is presented. pub fn has_next_page(&self) -> bool { self.next_url.is_some() diff --git a/src/fanbox/paginated_creator_posts.rs b/src/fanbox/paginated_creator_posts.rs index 5a0e60f..70a7fb8 100644 --- a/src/fanbox/paginated_creator_posts.rs +++ b/src/fanbox/paginated_creator_posts.rs @@ -45,6 +45,7 @@ impl PaginatedCreatorPosts { Ok(Self { client, pages }) } + #[allow(dead_code)] /// Get posts' data in specified page. /// * `index` - The index of the page pub async fn get_page(&self, index: usize) -> Option { @@ -72,6 +73,7 @@ impl PaginatedCreatorPosts { } } + #[allow(dead_code)] #[inline] /// Returns the total pages pub fn len(&self) -> usize { diff --git a/src/fanbox/post.rs b/src/fanbox/post.rs index 7f42476..9712b13 100644 --- a/src/fanbox/post.rs +++ b/src/fanbox/post.rs @@ -104,6 +104,27 @@ impl FanboxPostArticle { self.data["publishedDatetime"].as_str() } + #[inline] + pub fn tags(&self) -> Option> { + let mut list = Vec::new(); + let tags = &self.data["tags"]; + if tags.is_array() { + for i in tags.members() { + match i.as_str() { + Some(tag) => { + list.push(tag); + } + None => { + return None; + } + } + } + Some(list) + } else { + None + } + } + #[inline] pub fn title(&self) -> Option<&str> { self.data["title"].as_str() @@ -147,6 +168,7 @@ impl Debug for FanboxPostArticle { .field("next_post", &self.next_post()) .field("prev_post", &self.prev_post()) .field("published_datetime", &self.published_datetime()) + .field("tags", &self.tags()) .field("title", &self.title()) .field("updated_datetime", &self.updated_datetime()) .field("user_icon_url", &self.user_icon_url()) @@ -254,6 +276,27 @@ impl FanboxPostImage { self.data["publishedDatetime"].as_str() } + #[inline] + pub fn tags(&self) -> Option> { + let mut list = Vec::new(); + let tags = &self.data["tags"]; + if tags.is_array() { + for i in tags.members() { + match i.as_str() { + Some(tag) => { + list.push(tag); + } + None => { + return None; + } + } + } + Some(list) + } else { + None + } + } + #[inline] pub fn title(&self) -> Option<&str> { self.data["title"].as_str() @@ -297,6 +340,7 @@ impl Debug for FanboxPostImage { .field("next_post", &self.next_post()) .field("prev_post", &self.prev_post()) .field("published_datetime", &self.published_datetime()) + .field("tags", &self.tags()) .field("title", &self.title()) .field("updated_datetime", &self.updated_datetime()) .field("user_icon_url", &self.user_icon_url()) @@ -530,6 +574,27 @@ impl FanboxPost { self.get_json()["publishedDatetime"].as_str() } + #[inline] + pub fn tags(&self) -> Option> { + let mut list = Vec::new(); + let tags = &self.get_json()["tags"]; + if tags.is_array() { + for i in tags.members() { + match i.as_str() { + Some(tag) => { + list.push(tag); + } + None => { + return None; + } + } + } + Some(list) + } else { + None + } + } + #[inline] pub fn title(&self) -> Option<&str> { self.get_json()["title"].as_str()