From ff2c93ee8fbb7258c94daabc619dd2c2336dd553 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 10 Jul 2022 13:30:03 +0000 Subject: [PATCH] Update --- src/fanbox/article/block.rs | 12 +++++++-- src/fanbox/article/body.rs | 8 +++++- src/fanbox/comment.rs | 25 +++++++++++++++++- src/fanbox/comment_list.rs | 10 ++++++++ src/fanbox/creator.rs | 51 ++++++++++++++++++++++++++++++++++++- src/fanbox/plan.rs | 32 +++++++++++++++++++++++ 6 files changed, 133 insertions(+), 5 deletions(-) diff --git a/src/fanbox/article/block.rs b/src/fanbox/article/block.rs index 3f55fbe..85d263d 100644 --- a/src/fanbox/article/block.rs +++ b/src/fanbox/article/block.rs @@ -28,7 +28,11 @@ impl FanboxArticleParagraphBoldStyle { impl CheckUnkown for FanboxArticleParagraphBoldStyle { fn check_unknown(&self) -> Result<(), FanboxAPIError> { - check_json_keys!("offset"+, "length"+, "type",); + check_json_keys!( + "offset"+, + "length"+, + "type", + ); Ok(()) } } @@ -95,7 +99,11 @@ impl FanboxArticleParagraphBlock { impl CheckUnkown for FanboxArticleParagraphBlock { fn check_unknown(&self) -> Result<(), FanboxAPIError> { - check_json_keys!("styles", "text"+, "type",); + check_json_keys!( + "styles", + "text"+, + "type", + ); match self.styles() { Some(styles) => { for style in styles { diff --git a/src/fanbox/article/body.rs b/src/fanbox/article/body.rs index 1894f00..0267189 100644 --- a/src/fanbox/article/body.rs +++ b/src/fanbox/article/body.rs @@ -41,7 +41,13 @@ impl FanboxArticleBody { impl CheckUnkown for FanboxArticleBody { fn check_unknown(&self) -> Result<(), FanboxAPIError> { - check_json_keys!("blocks"+, "imageMap", "fileMap", "embedMap", "urlEmbedMap",); + check_json_keys!( + "blocks"+, + "imageMap", + "fileMap", + "embedMap", + "urlEmbedMap", + ); match self.blocks() { Some(blocks) => { for i in blocks { diff --git a/src/fanbox/comment.rs b/src/fanbox/comment.rs index 8985cd4..e60525c 100644 --- a/src/fanbox/comment.rs +++ b/src/fanbox/comment.rs @@ -87,7 +87,30 @@ impl FanboxComment { impl CheckUnkown for FanboxComment { fn check_unknown(&self) -> Result<(), super::error::FanboxAPIError> { - check_json_keys!("id"+, "body"+, "createdDatetime"+, "isLiked"+, "isOwn"+, "likeCount"+, "parentCommentId", "replies", "rootCommentId", "user": ["userId"+user_id, "name"+, "iconUrl"]); + check_json_keys!( + "id"+, + "body"+, + "createdDatetime"+, + "isLiked"+, + "isOwn"+, + "likeCount"+, + "parentCommentId", + "replies", + "rootCommentId", + "user": [ + "userId"+user_id, + "name"+, + "iconUrl", + ], + ); + match self.replies() { + Some(replies) => { + for i in replies { + i.check_unknown()?; + } + } + None => {} + } Ok(()) } } diff --git a/src/fanbox/comment_list.rs b/src/fanbox/comment_list.rs index a7fa19d..dcb773e 100644 --- a/src/fanbox/comment_list.rs +++ b/src/fanbox/comment_list.rs @@ -1,3 +1,4 @@ +use super::check::CheckUnkown; use super::comment::FanboxComment; #[cfg(test)] use super::post::FanboxPost; @@ -71,6 +72,15 @@ impl FanboxCommentList { } } +impl CheckUnkown for FanboxCommentList { + fn check_unknown(&self) -> Result<(), super::error::FanboxAPIError> { + for i in self.items.iter() { + i.check_unknown()?; + } + Ok(()) + } +} + impl Debug for FanboxCommentList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FanboxCommentList") diff --git a/src/fanbox/creator.rs b/src/fanbox/creator.rs index 3986942..1ff7cc4 100644 --- a/src/fanbox/creator.rs +++ b/src/fanbox/creator.rs @@ -1,7 +1,9 @@ +use super::check::CheckUnkown; use super::error::FanboxAPIError; use crate::fanbox_api::FanboxClientInternal; use crate::parser::json::parse_u64; use json::JsonValue; +use proc_macros::check_json_keys; use std::convert::From; use std::fmt::Debug; use std::ops::Deref; @@ -42,6 +44,17 @@ impl FanboxProfileImage { } } +impl CheckUnkown for FanboxProfileImage { + fn check_unknown(&self) -> Result<(), FanboxAPIError> { + check_json_keys!( + "id"+, + "imageUrl"+, + "thumbnailUrl", + ); + Ok(()) + } +} + impl Debug for FanboxProfileImage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FanboxProfileImage") @@ -53,7 +66,7 @@ impl Debug for FanboxProfileImage { } /// Profile item -#[derive(Debug)] +#[derive(proc_macros::CheckUnkown, Debug)] pub enum FanboxProfileItem { /// Image Image(FanboxProfileImage), @@ -100,6 +113,15 @@ impl FanboxProfileItems { } } +impl CheckUnkown for FanboxProfileItems { + fn check_unknown(&self) -> Result<(), FanboxAPIError> { + for i in self.list.iter() { + i.check_unknown()?; + } + Ok(()) + } +} + impl Debug for FanboxProfileItems { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.list.fmt(f) @@ -222,6 +244,33 @@ impl FanboxCreator { } } +impl CheckUnkown for FanboxCreator { + fn check_unknown(&self) -> Result<(), FanboxAPIError> { + check_json_keys!( + "creatorId"+, + "coverImageUrl", + "description"+, + "hasAdultContent"+, + "hasBoothShop"+, + "isAcceptingRequest"+, + "isFollowed"+, + "isStopped"+, + "isSupported"+, + "profileItems", + "profileLinks"+, + "user": [ + "userId"+user_id, + "iconUrl", + "name"+, + ], + ); + for i in self.profile_items()?.iter() { + i.check_unknown()?; + } + Ok(()) + } +} + impl Debug for FanboxCreator { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FanboxCreator") diff --git a/src/fanbox/plan.rs b/src/fanbox/plan.rs index 9cecf7b..06ca086 100644 --- a/src/fanbox/plan.rs +++ b/src/fanbox/plan.rs @@ -1,7 +1,9 @@ +use super::check::CheckUnkown; use super::error::FanboxAPIError; use crate::gettext; use crate::parser::json::parse_u64; use json::JsonValue; +use proc_macros::check_json_keys; use std::fmt::Debug; use std::ops::Deref; use std::ops::DerefMut; @@ -69,6 +71,27 @@ impl FanboxPlan { } } +impl CheckUnkown for FanboxPlan { + fn check_unknown(&self) -> Result<(), FanboxAPIError> { + check_json_keys!( + "id"+, + "coverImageUrl", + "creatorId"+, + "description"+, + "fee"+, + "hasAdultContent"+, + "paymentMethod", + "title"+, + "user": [ + "iconUrl", + "userId"+user_id, + "name"+, + ], + ); + Ok(()) + } +} + impl Debug for FanboxPlan { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FanboxPlan") @@ -128,6 +151,15 @@ impl FanboxPlanList { } } +impl CheckUnkown for FanboxPlanList { + fn check_unknown(&self) -> Result<(), FanboxAPIError> { + for i in self.list.iter() { + i.check_unknown()?; + } + Ok(()) + } +} + impl Debug for FanboxPlanList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_list().entries(self.list.iter()).finish()