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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::borrow::Cow;
use url::Url as StdUrl;

use lastfm_type::{LastfmType, Request, RequestParams};

// ----------------------------------------------------------------

#[derive(Debug)]
pub enum Params<'pr> {
    GetMobileSession {
        username: &'pr str,
        password: &'pr str,
    },
    GetSession { token: &'pr str, },
    GetToken,
}

impl<'pr> RequestParams for Params<'pr> {
    fn method(&self) -> &str {
        match *self {
            Params::GetMobileSession { .. } => "auth.getmobilesession",
            Params::GetSession { .. } => "auth.getsession",
            Params::GetToken => "auth.gettoken",
        }
    }

    fn needs_signature(&self) -> bool {
        true
    }

    fn needs_session_key(&self) -> bool {
        false
    }

    fn append_to(&self, url: &mut StdUrl) {
        let mut query = url.query_pairs_mut();
        match *self {
            Params::GetMobileSession { username, password } => {
                params!(query, [username: username, password: password], []);
            }
            Params::GetSession { token } => {
                params!(query, [token: token], []);
            }
            Params::GetToken => {}
        }
    }
}

// ----------------------------------------------------------------

#[derive(Deserialize, Debug)]
pub struct GetMobileSession<'dt> {
    pub name: Cow<'dt, str>,
    pub key: Cow<'dt, str>,
    pub subscriber: u32,
}

lastfm_t!(
    session,
    GetMobileSession,
    _GetMobileSession,
    Params,
    GetMobileSession,
    [username: &'rq str, password: &'rq str]
);

// ----------------------------------------------------------------

#[derive(Deserialize, Debug)]
pub struct GetSession<'dt> {
    pub name: Cow<'dt, str>,
    pub key: Cow<'dt, str>,
    pub subscriber: u32,
}

lastfm_t!(
    session,
    GetSession,
    _GetSession,
    Params,
    GetSession,
    [token: &'rq str]
);

// ----------------------------------------------------------------

#[derive(Deserialize, Debug)]
pub struct GetToken<'dt> {
    pub token: Cow<'dt, str>,
}

unwrapped_lastfm_t!(
    GetToken,
    Params,
    GetToken,
    []
);