diff options
author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-10-01 20:55:15 -0700 |
---|---|---|
committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-10-01 20:55:15 -0700 |
commit | e6ebf2c99a70bd5ee4e8d07097e6b128c3630714 (patch) | |
tree | 476947a6f2937737bc69ca073a2519bd9f15b1fe /commands/fav.rs | |
parent | af67981a2a1c28b3b5598f74d48bfd3a7490c91a (diff) |
extract commands and twitter model into modules
Diffstat (limited to 'commands/fav.rs')
-rw-r--r-- | commands/fav.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/commands/fav.rs b/commands/fav.rs new file mode 100644 index 0000000..3e2b00d --- /dev/null +++ b/commands/fav.rs @@ -0,0 +1,35 @@ +use tw; +use ::Queryer; + +use commands::Command; + +use std::str::FromStr; + +static FAV_TWEET_URL: &str = "https://api.twitter.com/1.1/favorites/create.json"; +static UNFAV_TWEET_URL: &str = "https://api.twitter.com/1.1/favorites/destroy.json"; + +pub static UNFAV: Command = Command { + keyword: "unfav", + params: 1, + exec: unfav +}; + +fn unfav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + // TODO handle this unwrap + let inner_twid = u64::from_str(&line).unwrap(); + let twete = tweeter.tweet_by_innerid(inner_twid).unwrap(); + queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id)); +} + +pub static FAV: Command = Command { + keyword: "fav", + params: 1, + exec: fav +}; + +fn fav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + // TODO handle this unwrap + let inner_twid = u64::from_str(&line).unwrap(); + let twete = tweeter.tweet_by_innerid(inner_twid).unwrap(); + queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id)); +} |