diff --git a/src/fanbox/item.rs b/src/fanbox/item.rs index 636c2f8..44befab 100644 --- a/src/fanbox/item.rs +++ b/src/fanbox/item.rs @@ -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") diff --git a/src/fanbox/item_list.rs b/src/fanbox/item_list.rs index fa67de1..51533cd 100644 --- a/src/fanbox/item_list.rs +++ b/src/fanbox/item_list.rs @@ -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 { 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")