This commit is contained in:
2022-07-11 01:32:29 +00:00
committed by GitHub
parent 60222a499b
commit 72bbac0b2e
2 changed files with 56 additions and 10 deletions

View File

@@ -1,5 +1,8 @@
use super::check::CheckUnknown;
use super::error::FanboxAPIError;
use crate::parser::json::parse_u64;
use json::JsonValue;
use proc_macros::check_json_keys;
use std::fmt::Debug;
/// To represent a fanbox item
@@ -144,6 +147,37 @@ impl FanboxItem {
}
}
impl CheckUnknown for FanboxItem {
fn check_unknown(&self) -> Result<(), FanboxAPIError> {
check_json_keys!(
"id"+,
"commentCount"+,
"coverImageUrl",
"cover": [
"type"+,
"url",
],
"creatorId"+,
"excerpt"+,
"feeRequired"+,
"hasAdultContent"+,
"isLiked"+,
"isRestricted"+,
"likeCount"+,
"publishedDatetime"+,
"tags"+,
"title"+,
"updatedDatetime"+,
"user": [
"name"+author_name,
"iconUrl",
"id"+,
],
);
Ok(())
}
}
impl Debug for FanboxItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FanboxItem")

View File

@@ -1,3 +1,4 @@
use super::check::CheckUnknown;
use super::error::FanboxAPIError;
use super::item::FanboxItem;
use crate::fanbox_api::FanboxClientInternal;
@@ -24,18 +25,20 @@ impl FanboxItemList {
pub async fn get_next_page(&self) -> Result<FanboxItemList, FanboxAPIError> {
match &self.next_url {
Some(url) => {
match self.client.get_url(url, gettext("Failed to get next page of the items."), gettext("Items data:")).await {
Some(data) => {
Self::new(&data["body"], Arc::clone(&self.client))
}
None => {
Err(FanboxAPIError::from("Failed to get next page."))
}
match self
.client
.get_url(
url,
gettext("Failed to get next page of the items."),
gettext("Items data:"),
)
.await
{
Some(data) => Self::new(&data["body"], Arc::clone(&self.client)),
None => Err(FanboxAPIError::from("Failed to get next page.")),
}
}
None => {
Err(FanboxAPIError::from("No next url, can not get next page."))
}
None => Err(FanboxAPIError::from("No next url, can not get next page.")),
}
}
@@ -70,6 +73,15 @@ impl FanboxItemList {
}
}
impl CheckUnknown for FanboxItemList {
fn check_unknown(&self) -> Result<(), FanboxAPIError> {
for i in self.items.iter() {
i.check_unknown()?;
}
Ok(())
}
}
impl Debug for FanboxItemList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FanboxItemList")