aboutsummaryrefslogtreecommitdiff
path: root/src/commands/follow.rs
blob: cd046c686a0b91b46962900239ee2ed606094de1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use display::DisplayInfo;
use tw;
use ::Queryer;

use commands::Command;

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,
    param_str: " <handle>",
    help_str: "Unfollow <handle>. No @ prefix in <handle>!"
};

fn unfl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) {
    let screen_name = line.trim();
    let result = match tweeter.current_profile() {
        Some(user_profile) => {
            queryer.do_api_post(FOLLOW_URL, &vec![("screen_name", &screen_name)], &tweeter.app_key, &user_profile.creds)
        },
        None => Err("No logged in user to unfollow from".to_owned())
    };
    match result {
        Ok(_resp) => (),
        Err(e) => display_info.status(format!("unfl request error: {}", e))
    }
}

pub static FOLLOW: Command = Command {
    keyword: "fl",
    params: 1,
    exec: fl,
    param_str: " <handle>",
    help_str: "Follow <handle>. No @ prefix in <handle>!"
};

fn fl(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) {
    let screen_name = line.trim();
    match tweeter.current_profile().map(|profile| profile.to_owned()) {
        Some(user_profile) => {
            display_info.status(
                format!(
                    "fl resp: {:?}",
                    queryer.do_api_post(
                        UNFOLLOW_URL,
                        &vec![("screen_name", &screen_name)],
                        &tweeter.app_key,
                        &user_profile.creds
                    )
                )
            )
        },
        None => display_info.status("No logged in user to follow from".to_owned())
    };
}