aboutsummaryrefslogtreecommitdiff
path: root/tw/events.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-01 23:25:46 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-01 23:25:46 -0700
commit943824e02fa771fa8350e4da90f2c9591ec4647e (patch)
treed04f8509e442e74e89cb6e7204d7fb4455d15ccd /tw/events.rs
parente6ebf2c99a70bd5ee4e8d07097e6b128c3630714 (diff)
yank out more parts, decouple events and display
Diffstat (limited to 'tw/events.rs')
-rw-r--r--tw/events.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tw/events.rs b/tw/events.rs
new file mode 100644
index 0000000..0541b0a
--- /dev/null
+++ b/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<String, serde_json::Value>) -> Option<Event> {
+ 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 }
+ }
+ }
+}