diff --git a/src/fanbox/post.rs b/src/fanbox/post.rs index 76b2ed0..7908aa5 100644 --- a/src/fanbox/post.rs +++ b/src/fanbox/post.rs @@ -77,6 +77,16 @@ impl FanboxPostArticle { } } + #[inline] + pub fn next_post(&self) -> Option { + let obj = &self.data["nextPost"]; + 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() @@ -122,6 +132,7 @@ impl Debug for FanboxPostArticle { .field("is_liked", &self.is_liked()) .field("is_restricted", &self.is_restricted()) .field("like_count", &self.like_count()) + .field("next_post", &self.next_post()) .field("published_datetime", &self.published_datetime()) .field("title", &self.title()) .field("updated_datetime", &self.updated_datetime()) @@ -132,6 +143,50 @@ impl Debug for FanboxPostArticle { } } +/// A reference to another post +pub struct FanboxPostRef { + /// Raw data + pub data: JsonValue, + /// The api client + client: Arc, +} + +impl FanboxPostRef { + #[inline] + pub fn id(&self) -> Option { + parse_u64(&self.data["id"]) + } + + #[inline] + /// Create a new instance + pub fn new(data: &JsonValue, client: Arc) -> Self { + Self { + data: data.clone(), + client, + } + } + + #[inline] + pub fn published_datetime(&self) -> Option<&str> { + self.data["publishedDatetime"].as_str() + } + + #[inline] + pub fn title(&self) -> Option<&str> { + self.data["title"].as_str() + } +} + +impl Debug for FanboxPostRef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("FanboxPostRef") + .field("id", &self.id()) + .field("published_datetime", &self.published_datetime()) + .field("title", &self.title()) + .finish_non_exhaustive() + } +} + #[derive(Debug)] /// The fanbox's post pub enum FanboxPost {