From 781981f333345482e93ed35453e98e519bb7cc5e Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 2 Oct 2017 01:27:08 -0700 Subject: move everything to src/ --- src/tw/events.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/tw/events.rs (limited to 'src/tw/events.rs') diff --git a/src/tw/events.rs b/src/tw/events.rs new file mode 100644 index 0000000..0541b0a --- /dev/null +++ b/src/tw/events.rs @@ -0,0 +1,44 @@ +extern crate serde_json; + +pub enum Event { + Deleted { user_id: String, twete_id: String }, + RT_RT { user_id: String, twete_id: String }, + Fav_RT { user_id: String, twete_id: String }, + Fav { user_id: String, twete_id: String }, + Unfav { user_id: String, twete_id: String }, + Followed { user_id: String }, + Unfollowed { user_id: String } +} + +impl Event { + pub fn from_json(structure: serde_json::Map) -> Option { + match &structure["event"].as_str().unwrap() { + &"follow" => Some(Event::Followed { + user_id: structure["source"]["id_str"].as_str().unwrap().to_owned() + }), + &"unfollow" => Some(Event::Unfollowed { + user_id: structure["source"]["id_str"].as_str().unwrap().to_owned() + }), + &"favorite" => Some(Event::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(Event::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(Event::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(Event::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 } + } + } +} -- cgit v1.1