use structures::comment_list::CommentList;
use structures::submission::FlairList;
use structures::user::User;
use structures::subreddit::Subreddit;
use errors::APIError;
pub trait Votable {
fn score(&self) -> i64;
fn likes(&self) -> Option<bool>;
fn upvote(&self) -> Result<(), APIError>;
fn downvote(&self) -> Result<(), APIError>;
fn cancel_vote(&self) -> Result<(), APIError>;
}
pub trait PageListing {
fn before(&self) -> Option<String>;
fn after(&self) -> Option<String>;
fn modhash(&self) -> Option<String>;
}
pub trait Created {
fn created(&self) -> i64;
fn created_utc(&self) -> i64;
}
pub trait Editable {
fn edited(&self) -> bool;
fn edited_time(&self) -> Option<i64>;
fn edit(&mut self, text: &str) -> Result<(), APIError>;
fn body(&self) -> Option<String>;
fn body_html(&self) -> Option<String>;
}
pub trait Content {
fn author(&self) -> User;
fn author_flair_text(&self) -> Option<String>;
fn author_flair_css(&self) -> Option<String>;
fn subreddit(&self) -> Subreddit;
fn delete(self) -> Result<(), APIError>;
fn name(&self) -> &str;
}
pub trait Commentable<'a> {
fn reply_count(&self) -> u64;
fn reply(&self, &str) -> Result<(), APIError>;
fn replies(self) -> Result<CommentList<'a>, APIError>;
}
pub trait Stickable {
fn stickied(&self) -> bool;
fn stick(&mut self) -> Result<(), APIError>;
fn unstick(&mut self) -> Result<(), APIError>;
fn toggle_sticky(&mut self) -> Result<(), APIError> {
if self.stickied() {
self.unstick()
} else {
self.stick()
}
}
}
pub trait Lockable {
fn locked(&self) -> bool;
fn lock(&mut self) -> Result<(), APIError>;
fn unlock(&mut self) -> Result<(), APIError>;
fn toggle_lock(&mut self) -> Result<(), APIError> {
if self.locked() {
self.unlock()
} else {
self.lock()
}
}
}
pub trait Reportable {
fn report(&self, reason: &str) -> Result<(), APIError>;
fn report_count(&self) -> Option<u64>;
}
pub trait Flairable {
fn get_flair_text(&self) -> Option<String>;
fn get_flair_css(&self) -> Option<String>;
fn flair_options(&self) -> Result<FlairList, APIError>;
fn flair(&self, template: &str) -> Result<(), APIError>;
}
pub trait Visible {
fn hidden(&self) -> bool;
fn hide(&mut self) -> Result<(), APIError>;
fn show(&mut self) -> Result<(), APIError>;
fn toggle_hidden(&mut self) -> Result<(), APIError> {
if self.hidden() {
self.show()
} else {
self.hide()
}
}
}
pub trait Distinguishable {
fn distinguished(&self) -> Option<String>;
fn distinguish(&mut self) -> Result<(), APIError>;
fn undistinguish(&mut self) -> Result<(), APIError>;
fn toggle_distinguish(&mut self) -> Result<(), APIError> {
if let Some(_) = self.distinguished() {
self.undistinguish()
} else {
self.distinguish()
}
}
}