aboutsummaryrefslogtreecommitdiff
path: root/src/call/account.rs
blob: 08bf077e197c8910628b8cdc1ba176e536477b5e (plain) (blame)
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
use super::Call;

use std::collections::BTreeMap;

// Contains login information. Used to create an API session.
pub(crate) struct Login<'a> {
    pub(crate) user: &'a str,
    pub(crate) pass: &'a str,
    pub(crate) case_insensitive: bool,
}

impl From<Login<'_>> for xmlrpc::Value {
    fn from(login: Login<'_>) -> Self {
        let mut map = BTreeMap::new();

        map.insert("user".into(), login.user.into());
        map.insert("pass".into(), login.pass.into());
        map.insert("case-insensitive".into(), login.case_insensitive.into());

        xmlrpc::Value::Struct(map)
    }
}

impl Call for Login<'_> {
    fn method_name(&self) -> &'static str {
        "account.login"
    }
    fn expected(&self) -> &'static [i32] {
        &[1000]
    }
}

// Contains no information. This just signals to the server
// that it should end the session.
pub(crate) struct Logout;

impl From<Logout> for xmlrpc::Value {
    fn from(_logout: Logout) -> Self {
        xmlrpc::Value::Nil
    }
}

impl Call for Logout {
    fn method_name(&self) -> &'static str {
        "account.logout"
    }
    fn expected(&self) -> &'static [i32] {
        &[1500]
    }
}