This commit is contained in:
2022-07-06 13:40:02 +00:00
committed by GitHub
parent 31b1af3b78
commit c0fa6db0cb
3 changed files with 69 additions and 0 deletions

View File

@@ -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()

View File

@@ -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<FanboxItemList> {
@@ -72,6 +73,7 @@ impl PaginatedCreatorPosts {
}
}
#[allow(dead_code)]
#[inline]
/// Returns the total pages
pub fn len(&self) -> usize {

View File

@@ -104,6 +104,27 @@ impl FanboxPostArticle {
self.data["publishedDatetime"].as_str()
}
#[inline]
pub fn tags(&self) -> Option<Vec<&str>> {
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<Vec<&str>> {
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<Vec<&str>> {
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()