diff --git a/proc_macros/proc_macros.rs b/proc_macros/proc_macros.rs index 6cecba4..52c06f0 100644 --- a/proc_macros/proc_macros.rs +++ b/proc_macros/proc_macros.rs @@ -136,7 +136,7 @@ pub fn fanbox_api_test(item: TokenStream) -> TokenStream { async fn #name() { match std::env::var("FANBOX_COOKIES_FILE") { Ok(path) => { - let client = FanboxClient::new(); + let client = crate::fanbox_api::FanboxClient::new(); if !client.init(Some(path)) { panic!("Failed to initiailze the client."); } @@ -184,7 +184,7 @@ pub fn fanbox_api_quick_test(item: TokenStream) -> TokenStream { async fn #name() { match std::env::var("FANBOX_COOKIES_FILE") { Ok(path) => { - let client = FanboxClient::new(); + let client = crate::fanbox_api::FanboxClient::new(); if !client.init(Some(path)) { panic!("Failed to initiailze the client."); } diff --git a/src/fanbox/paginated_creator_posts.rs b/src/fanbox/paginated_creator_posts.rs index d6b71eb..5a0e60f 100644 --- a/src/fanbox/paginated_creator_posts.rs +++ b/src/fanbox/paginated_creator_posts.rs @@ -1,7 +1,5 @@ use super::error::FanboxAPIError; use super::item_list::FanboxItemList; -#[cfg(test)] -use crate::fanbox_api::FanboxClient; use crate::fanbox_api::FanboxClientInternal; use crate::gettext; use json::JsonValue; diff --git a/src/fanbox/post.rs b/src/fanbox/post.rs index 7908aa5..fd661c1 100644 --- a/src/fanbox/post.rs +++ b/src/fanbox/post.rs @@ -1,6 +1,7 @@ use crate::fanbox_api::FanboxClientInternal; use crate::parser::json::parse_u64; use json::JsonValue; +use proc_macros::fanbox_api_test; use std::fmt::Debug; use std::sync::Arc; @@ -87,6 +88,16 @@ impl FanboxPostArticle { } } + #[inline] + pub fn prev_post(&self) -> Option { + let obj = &self.data["prevPost"]; + if obj.is_object() { + Some(FanboxPostRef::new(obj, Arc::clone(&self.client))) + } else { + None + } + } + #[inline] pub fn published_datetime(&self) -> Option<&str> { self.data["publishedDatetime"].as_str() @@ -133,6 +144,7 @@ impl Debug for FanboxPostArticle { .field("is_restricted", &self.is_restricted()) .field("like_count", &self.like_count()) .field("next_post", &self.next_post()) + .field("prev_post", &self.prev_post()) .field("published_datetime", &self.published_datetime()) .field("title", &self.title()) .field("updated_datetime", &self.updated_datetime()) @@ -152,6 +164,16 @@ pub struct FanboxPostRef { } impl FanboxPostRef { + pub async fn get_post(&self) -> Option { + match self.id() { + Some(id) => match self.client.get_post_info(id).await { + Some(s) => Some(FanboxPost::new(&s["body"], Arc::clone(&self.client))), + None => None, + }, + None => None, + } + } + #[inline] pub fn id(&self) -> Option { parse_u64(&self.data["id"]) @@ -209,3 +231,33 @@ impl FanboxPost { } } } + +fanbox_api_test!(test_get_post_info, { + match client.get_post_info(4070200).await { + Some(data) => match data { + FanboxPost::Article(data) => { + println!("{:?}", data); + match data.next_post() { + Some(r) => { + println!("{:?}", r); + match r.get_post().await { + Some(r) => { + println!("{:?}", r); + } + None => { + panic!("Failed to get next post.") + } + } + } + None => {} + } + } + FanboxPost::Unknown(data) => { + println!("{}", data); + } + }, + None => { + panic!("Failed to get the post info(第253話 【壁紙プレゼント】ひんやりレモンころねちゃん🍋)."); + } + } +}); diff --git a/src/fanbox_api.rs b/src/fanbox_api.rs index c36a2fd..8e50987 100644 --- a/src/fanbox_api.rs +++ b/src/fanbox_api.rs @@ -384,11 +384,6 @@ impl Deref for FanboxClient { } } -fanbox_api_quick_test!( - test_get_post_info, - client.get_post_info(4070200), - "Failed to get the post info(第253話 【壁紙プレゼント】ひんやりレモンころねちゃん🍋)." -); fanbox_api_quick_test!( test_list_home_post, client.list_home_post(10),