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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::convert::Into;
use std::borrow::Cow;
use url::Url as StdUrl;
use lastfm_type::{LastfmType, Request, RequestParams};
use super::common::{Url, Image, Id2, Streamable, Rank, str_to_val};
#[derive(Debug)]
pub enum Params<'pr> {
Phantom(&'pr ()),
GetTopArtists {
country: &'pr str,
limit: Option<u32>,
page: Option<u32>,
},
GetTopTracks {
country: &'pr str,
location: Option<&'pr str>,
limit: Option<u32>,
page: Option<u32>,
},
}
impl<'pr> RequestParams for Params<'pr> {
fn method(&self) -> &str {
match *self {
Params::GetTopArtists { .. } => "geo.gettopartists",
Params::GetTopTracks { .. } => "geo.gettoptracks",
Params::Phantom(_) => panic!("this is a dummy item")
}
}
fn needs_signature(&self) -> bool {
false
}
fn needs_session_key(&self) -> bool {
false
}
fn append_to(&self, url: &mut StdUrl) {
let mut query = url.query_pairs_mut();
match *self {
Params::GetTopArtists {
country,
limit,
page,
} => {
query.append_pair("country", country);
if let Some(limit) = limit {
query.append_pair("limit", &limit.to_string());
}
if let Some(page) = page {
query.append_pair("page", &page.to_string());
}
}
Params::GetTopTracks {
country,
location,
limit,
page,
} => {
query.append_pair("country", country);
if let Some(location) = location {
query.append_pair("location", location);
}
if let Some(limit) = limit {
query.append_pair("limit", &limit.to_string());
}
if let Some(page) = page {
query.append_pair("page", &page.to_string());
}
}
Params::Phantom(_) => panic!("this is a dummy item")
}
}
}
#[derive(Deserialize, Debug)]
pub struct Artist<'dt> {
pub name: Cow<'dt, str>,
pub mbid: Option<&'dt str>,
pub url: Url<'dt>,
#[serde(deserialize_with = "str_to_val")]
pub streamable: u32,
pub image: Vec<Image<'dt>>,
}
#[derive(Deserialize, Debug)]
pub struct GetTopArtists<'dt> {
#[serde(borrow)]
pub artist: Option<Vec<Artist<'dt>>>,
}
lastfm_t!(
topartists,
GetTopArtists,
_TopArtists,
Params,
GetTopArtists,
[country: &'rq str, limit: Option<u32>, page: Option<u32>]
);
#[derive(Deserialize, Debug)]
pub struct Track<'dt> {
pub name: Cow<'dt, str>,
pub mbid: Option<&'dt str>,
pub url: Url<'dt>,
pub streamable: Option<Streamable>,
pub artist: Id2<'dt>,
pub image: Vec<Image<'dt>>,
#[serde(rename = "@attr")]
pub rank: Option<Rank>,
}
#[derive(Deserialize, Debug)]
pub struct GetTopTracks<'dt> {
#[serde(borrow)]
pub track: Option<Vec<Track<'dt>>>,
}
lastfm_t!(
tracks,
GetTopTracks,
_TopTracks,
Params,
GetTopTracks,
[
country: &'rq str,
location: Option<&'rq str>,
limit: Option<u32>,
page: Option<u32>
]
);