diff --git a/src/fanbox/item_list.rs b/src/fanbox/item_list.rs index 7f1eac0..758547b 100644 --- a/src/fanbox/item_list.rs +++ b/src/fanbox/item_list.rs @@ -17,6 +17,33 @@ pub struct FanboxItemList { } impl FanboxItemList { + /// Get next page. + /// # Note + /// If no next page presented, will return a error. + 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.")) + } + } + } + None => { + Err(FanboxAPIError::from("No next url, can not get next page.")) + } + } + } + + /// Returns true if next page is presented. + pub fn has_next_page(&self) -> bool { + self.next_url.is_some() + } + + /// Create a new instance pub fn new( value: &JsonValue, client: Arc, diff --git a/src/fanbox/paginated_creator_posts.rs b/src/fanbox/paginated_creator_posts.rs index 71ad3c5..d6b71eb 100644 --- a/src/fanbox/paginated_creator_posts.rs +++ b/src/fanbox/paginated_creator_posts.rs @@ -105,7 +105,17 @@ fanbox_api_test!(test_paginate_creator_posts, { if pages.len() > 0 { match pages.get_page(0).await { Some(data) => { - println!("{:?}", data) + println!("{:?}", data); + if data.has_next_page() { + match data.get_next_page().await { + Ok(data) => { + println!("{:?}", data); + } + Err(e) => { + println!("{}", e); + } + } + } } None => {} }