aboutsummaryrefslogtreecommitdiff
path: root/tw/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tw/mod.rs')
-rw-r--r--tw/mod.rs157
1 files changed, 2 insertions, 155 deletions
diff --git a/tw/mod.rs b/tw/mod.rs
index efc070b..540d4d0 100644
--- a/tw/mod.rs
+++ b/tw/mod.rs
@@ -11,6 +11,8 @@ use std::io::Write;
use std::fs::OpenOptions;
+pub mod events;
+
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub id: String,
@@ -28,161 +30,6 @@ impl Default for User {
}
}
-pub mod events {
- extern crate termion;
- use self::termion::color;
-
- extern crate serde_json;
-
- pub struct Deleted {
- user_id: String,
- twete_id: String
- }
-
- pub struct RT_RT {
- user_id: String,
- twete_id: String
- }
-
- pub struct Fav_RT {
- user_id: String,
- twete_id: String
- }
-
- pub struct Fav {
- user_id: String,
- twete_id: String
- }
-
- pub struct Unfav {
- user_id: String,
- twete_id: String
- }
-
- pub struct Followed {
- user_id: String
- }
-
- pub struct Unfollowed {
- user_id: String
- }
-
- impl Event for Deleted {
- fn render(self: Box<Self>, _tweeter: &::tw::TwitterCache) { }
- }
- impl Event for RT_RT {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- println!("---------------------------------");
- {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!(" +rt_rt : {} (@{})", user.name, user.handle);
- }
- {
- ::render_twete(&self.twete_id, tweeter);
- }
- println!("");
- }
- }
- impl Event for Fav_RT {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- println!("---------------------------------");
- {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!(" +rt_fav : {} (@{})", user.name, user.handle);
- }
- {
- ::render_twete(&self.twete_id, tweeter);
- }
- println!("");
- }
- }
- impl Event for Fav {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- println!("---------------------------------");
- {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!("{} +fav : {} (@{}){}", color::Fg(color::Yellow), user.name, user.handle, color::Fg(color::Reset));
- }
- {
- ::render_twete(&self.twete_id, tweeter);
- }
- println!("");
- }
- }
- impl Event for Unfav {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- println!("---------------------------------");
- {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!("{} -fav : {} (@{}){}", color::Fg(color::Yellow), user.name, user.handle, color::Fg(color::Reset));
- }
- {
- ::render_twete(&self.twete_id, tweeter);
- }
- println!("");
- }
- }
- impl Event for Followed {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!("---------------------------------");
- println!(" +fl : {} (@{})", user.name, user.handle);
- println!("");
- }
- }
- impl Event for Unfollowed {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache) {
- let user = tweeter.retrieve_user(&self.user_id).unwrap();
- println!("---------------------------------");
- println!(" -fl : {} (@{})", user.name, user.handle);
- println!("");
- }
- }
-
- /*
- impl Event for Blocked {
-
- }
- */
-
- pub trait Event {
- fn render(self: Box<Self>, tweeter: &::tw::TwitterCache);
- }
-
- impl Event {
- pub fn from_json(structure: serde_json::Map<String, serde_json::Value>) -> Option<Box<Event>> {
- match &structure["event"].as_str().unwrap() {
- &"follow" => Some(Box::new(Followed {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned()
- })),
- &"unfollow" => Some(Box::new(Unfollowed {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned()
- })),
- &"favorite" => Some(Box::new(Fav {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned(),
- twete_id: structure["target_object"]["id_str"].as_str().unwrap().to_owned()
- })),
- &"unfavorite" => Some(Box::new(Unfav {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned(),
- twete_id: structure["target_object"]["id_str"].as_str().unwrap().to_owned()
- })),
- &"favorited_retweet" => Some(Box::new(Fav_RT {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned(),
- twete_id: structure["target_object"]["id_str"].as_str().unwrap().to_owned()
- })),
- &"retweeted_retweet" => Some(Box::new(RT_RT {
- user_id: structure["source"]["id_str"].as_str().unwrap().to_owned(),
- twete_id: structure["target_object"]["id_str"].as_str().unwrap().to_owned()
- })),
-// &"blocked" => Blocked { },
-// &"unblocked" => Unblocked { },
-// &"quoted_tweet" => ???,
- e => { println!("unrecognized event: {}", e); None }
- }
- }
- }
-}
-
impl User {
pub fn from_json(json: serde_json::Value) -> Option<User> {
if let serde_json::Value::Object(json_map) = json {