This commit is contained in:
2022-06-28 14:27:20 +00:00
committed by GitHub
parent 4fafc3c3de
commit 1cf3e3cbe2
2 changed files with 56 additions and 11 deletions

View File

@@ -193,7 +193,9 @@ pub fn fanbox_api_quick_test(item: TokenStream) -> TokenStream {
return;
}
match #expr.await {
Some(_) => {}
Some(data) => {
println!("{:?}", data);
}
None => {
panic!("{}", #errmsg);
}

View File

@@ -1,6 +1,7 @@
use crate::ext::atomic::AtomicQuick;
use crate::ext::replace::ReplaceWith2;
use crate::ext::rw_lock::GetRwLock;
use crate::fanbox::item_list::FanboxItemList;
use crate::fanbox::paginated_creator_posts::PaginatedCreatorPosts;
use crate::gettext;
use crate::opthelper::get_helper;
@@ -232,6 +233,25 @@ impl FanboxClientInternal {
None => false,
}
}
#[allow(dead_code)]
/// Paginate creator posts
/// * `creator_id` - The id of the creator
pub async fn paginate_creator_post<S: AsRef<str> + ?Sized>(
&self,
creator_id: &S,
) -> Option<JsonValue> {
self.auto_init();
handle_data!(
self.client.get_with_param(
"https://api.fanbox.cc/post.paginateCreator",
json::object! {"creatorId": creator_id.as_ref()},
None,
),
gettext("Failed to paginate creator post:"),
gettext("Paginated data:")
)
}
}
/// Fanbox API Client
@@ -248,6 +268,38 @@ impl FanboxClient {
}
}
#[allow(dead_code)]
/// List home page's post list. All supported and followed creators' posts are included.
/// * `limit` - The max count. 10 is used on Fanbox website.
pub async fn list_home_post(&self, limit: u64) -> Option<FanboxItemList> {
match self.client.list_home_post(limit).await {
Some(s) => match FanboxItemList::new(&s["body"], Arc::clone(&self.client)) {
Ok(item) => Some(item),
Err(e) => {
println!("{}", e);
None
}
},
None => None,
}
}
#[allow(dead_code)]
/// List supported creators' posts.
/// * `limit` - The max count. 10 is used on Fanbox website.
pub async fn list_supporting_post(&self, limit: u64) -> Option<FanboxItemList> {
match self.client.list_supporting_post(limit).await {
Some(s) => match FanboxItemList::new(&s["body"], Arc::clone(&self.client)) {
Ok(item) => Some(item),
Err(e) => {
println!("{}", e);
None
}
},
None => None,
}
}
#[allow(dead_code)]
/// Paginate creator posts
/// * `creator_id` - The id of the creator
@@ -255,16 +307,7 @@ impl FanboxClient {
&self,
creator_id: &S,
) -> Option<PaginatedCreatorPosts> {
self.auto_init();
match handle_data!(
self.client.client.get_with_param(
"https://api.fanbox.cc/post.paginateCreator",
json::object! {"creatorId": creator_id.as_ref()},
None,
),
gettext("Failed to paginate creator post:"),
gettext("Paginated data:")
) {
match self.client.paginate_creator_post(creator_id).await {
Some(s) => match PaginatedCreatorPosts::new(&s, Arc::clone(&self.client)) {
Ok(re) => Some(re),
Err(e) => {