aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-16 23:25:12 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-17 00:11:56 -0700
commitf3f938d2aa9cd1cc077fec386e5c0751ade6839c (patch)
tree3d30296e225903ec29033d6b69e87d3a1ab850a2
parent2ab8a00fdd6a8e9386d08c83cb7318ceb3c3c31a (diff)
add commands to follow/unfollow
-rw-r--r--src/commands/follow.rs33
-rw-r--r--src/commands/mod.rs3
2 files changed, 36 insertions, 0 deletions
diff --git a/src/commands/follow.rs b/src/commands/follow.rs
new file mode 100644
index 0000000..0da07a8
--- /dev/null
+++ b/src/commands/follow.rs
@@ -0,0 +1,33 @@
+use tw;
+use ::Queryer;
+
+use commands::Command;
+
+use std::str::FromStr;
+
+static FOLLOW_URL: &str = "https://api.twitter.com/1.1/friendships/create.json";
+static UNFOLLOW_URL: &str = "https://api.twitter.com/1.1/friendships/destroy.json";
+
+pub static UNFOLLOW: Command = Command {
+ keyword: "unfl",
+ params: 1,
+ exec: unfl
+};
+
+fn unfl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
+ // TODO handle this unwrap
+ let screen_name = line.trim(); //u64::from_str(&line).unwrap();
+ queryer.do_api_post(&format!("{}?screen_name={}", FOLLOW_URL, screen_name));
+}
+
+pub static FOLLOW: Command = Command {
+ keyword: "fl",
+ params: 1,
+ exec: fl
+};
+
+fn fl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
+ // TODO handle this unwrap
+ let screen_name = line.trim(); //u64::from_str(&line).unwrap();
+ println!("fl resp: {:?}", queryer.do_api_post(&format!("{}?screen_name={}", UNFOLLOW_URL, screen_name)));
+}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 51e0e53..4052326 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -13,6 +13,7 @@ mod look_up;
mod view;
mod quit;
mod fav;
+mod follow;
pub static COMMANDS: &[&Command] = &[
&show_cache::SHOW_CACHE,
@@ -21,6 +22,8 @@ pub static COMMANDS: &[&Command] = &[
&look_up::LOOK_UP_TWEET,
&view::VIEW,
&view::VIEW_THREAD,
+ &follow::FOLLOW,
+ &follow::UNFOLLOW,
&fav::UNFAV,
&fav::FAV,
&twete::DEL,