use crate::entity::*;
pub struct CreateAccount {
pub short_name: ShortName,
pub author_name: Option<AuthorName>,
pub author_url: Option<AuthorUrl>,
}
impl CreateAccount {
pub fn new(short_name: String) -> Self {
assert!(!short_name.is_empty(), "short name is required");
Self {
short_name: ShortName::new(short_name),
author_name: None,
author_url: None,
}
}
pub fn with_raw(
short_name: String,
author_name: Option<String>,
author_url: Option<String>,
) -> Self {
let author_name = match author_name {
Some(name) => Some(AuthorName::new(name)),
None => None
};
let author_url = match author_url {
Some(url) => Some(AuthorUrl::new(url)),
None => None
};
Self {
short_name: ShortName::new(short_name),
author_name,
author_url,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut CreateAccount) -> Pin<Box<dyn Future<Output = Ret<Account>> + 'a>>> ) -> Ret<Account> {
f(self).await
}
}
pub struct EditAccountInfo {
pub access_token: String,
pub short_name: ShortName,
pub author_name: Option<AuthorName>,
pub author_url: Option<AuthorUrl>,
}
use std::pin::Pin;
use std::future::Future;
pub type Ret<T> = Result<T, Box<dyn std::error::Error>> ;
impl EditAccountInfo {
pub fn new(access_token: String, short_name: String) -> Self {
Self {
access_token,
short_name: ShortName::new(short_name),
author_name: None,
author_url: None,
}
}
pub fn with_raw(
access_token: String,
short_name: String,
author_name: Option<String>,
author_url: Option<String>,
) -> Self {
let author_name = match author_name {
Some(name) => Some(AuthorName(name)),
None => None
};
let author_url = match author_url {
Some(url) => Some(AuthorUrl(url)),
None => None
};
Self {
access_token,
short_name: ShortName::new(short_name),
author_name,
author_url,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut EditAccountInfo) -> Pin<Box<dyn Future<Output = Ret<Account>> + 'a>>> ) -> Ret<Account> {
f(self).await
}
}
pub struct GetAccountInfo {
pub access_token: String,
pub fields: Fields,
}
impl GetAccountInfo {
pub fn new(access_token: String) -> Self {
Self {
access_token,
fields: Fields::new(vec![]),
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut GetAccountInfo) -> Pin<Box<dyn Future<Output = Ret<Account>> + 'a>>> ) -> Ret<Account> {
f(self).await
}
}
pub struct RevokeAccessToken {
pub access_token: String,
}
impl RevokeAccessToken {
pub fn new(access_token: String) -> Self {
Self {
access_token,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut RevokeAccessToken) -> Pin<Box<dyn Future<Output = Ret<Account>> + 'a>>> ) -> Ret<Account> {
f(self).await
}
}
pub struct CreatePage {
pub access_token: String,
pub title: Title,
pub author_name: AuthorName,
pub author_url: AuthorUrl,
pub content: Content,
pub return_content: bool,
}
impl CreatePage {
pub fn new(access_token: String, title: String, content: Content, return_content: bool) -> Self {
Self {
access_token,
title: Title::new(title),
author_name: AuthorName::new("".into()),
author_url: AuthorUrl::new("".into()),
content,
return_content,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut CreatePage) -> Pin<Box<dyn Future<Output = Ret<Page>> + 'a>>> ) -> Ret<Page> {
f(self).await
}
}
pub struct EditPage {
pub access_token: String,
pub path: String,
pub title: Title,
pub content: Content,
pub author_name: AuthorName,
pub author_url: AuthorUrl,
pub return_content: bool,
}
impl EditPage {
pub fn new(access_token: String, path: String, title: String, content: Content, return_content: bool) -> Self {
Self {
access_token,
title: Title::new(title),
path,
author_name: AuthorName::new("".into()),
author_url: AuthorUrl::new("".into()),
content,
return_content,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut EditPage) -> Pin<Box<dyn Future<Output = Ret<Page>> + 'a>>> ) -> Ret<Page> {
f(self).await
}
}
pub struct GetPage {
pub path: String,
pub return_content: bool,
}
impl GetPage {
pub fn new( path: String, return_content: bool) -> Self {
Self {
path,
return_content,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut GetPage) -> Pin<Box<dyn Future<Output = Ret<Page>> + 'a>>> ) -> Ret<Page> {
f(self).await
}
}
pub struct GetPageList {
pub access_token: String,
pub offset: u32,
pub limit: Limit,
}
impl GetPageList {
pub fn new(access_token: String, offset: u32, ) -> Self {
Self {
access_token,
offset,
limit: Limit::new(),
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut GetPageList) -> Pin<Box<dyn Future<Output = Ret<PageList>> + 'a>>> ) -> Ret<PageList> {
f(self).await
}
}
pub struct GetViews {
pub path: String,
pub year: Option<Year>,
pub month: Option<Month>,
pub day: Option<Day>,
pub hour: Option<Hour>,
}
impl GetViews {
pub fn new(path: String, year: u16, ) -> Self {
Self {
path,
year: Some(Year::new(year)),
month: None,
day: None,
hour: None,
}
}
pub async fn run(&mut self, f: Box<dyn for<'a> Fn(&'a mut GetViews) -> Pin<Box<dyn Future<Output = Ret<PageViews>> + 'a>>> ) -> Ret<PageViews> {
f(self).await
}
}