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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use super::{Cursors, ExternalUrls, Followers, Image, ItemType};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Artist {
/// Known external URLs for this artist.
pub external_urls: ExternalUrls,
/// Information about the followers of the artist.
pub followers: Followers,
/// A list of the genres the artist is associated with. If not yet classified, the array is empty.
pub genres: Vec<String>,
/// A link to the Web API endpoint providing full details of the artist.
pub href: String,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the artist.
pub id: String,
/// Images of the artist in various sizes, widest first.
pub images: Vec<Image>,
/// The name of the artist.
pub name: String,
/// The popularity of the artist. The value will be between 0 and 100, with 100 being the most popular.
/// The artist's popularity is calculated from the popularity of all the artist's tracks.
pub popularity: u8,
/// The object type.
///
/// Allowed values: "artist"
#[serde(rename = "type")]
pub type_: ItemType,
/// The [Spotify URI](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the artist.
pub uri: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SimplifiedArtist {
/// Known external URLs for this artist.
pub external_urls: ExternalUrls,
/// A link to the Web API endpoint providing full details of the artist.
pub href: String,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the artist.
pub id: String,
/// The name of the artist.
pub name: String,
/// The object type.
///
/// Allowed values: "artist"
#[serde(rename = "type")]
pub type_: ItemType,
/// The [Spotify URI](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the artist.
pub uri: String,
}
impl From<Artist> for SimplifiedArtist {
fn from(artist: Artist) -> Self {
Self {
external_urls: artist.external_urls,
href: artist.href,
id: artist.id,
name: artist.name,
type_: artist.type_,
uri: artist.uri,
}
}
}
/// Spotify catalog information for several artists
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Artists {
pub artists: Vec<Option<Artist>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FollowedArtist {
/// A link to the Web API endpoint returning the full result of the request.
pub href: String,
/// The maximum number of items in the response (as set in the query or by default).
pub limit: usize,
/// URL to the next page of items.
pub next: Option<String>,
/// The cursors used to find the next set of items.
pub cursors: Cursors,
/// The total number of items available to return.
pub total: usize,
pub items: Vec<Artist>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FollowedArtists {
pub artists: FollowedArtist,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn artist() {
let json = r#"
{
"external_urls": {
"spotify": "string"
},
"followers": {
"href": "string",
"total": 0
},
"genres": ["Prog rock", "Grunge"],
"href": "string",
"id": "string",
"images": [
{
"url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
"height": 300,
"width": 300
}
],
"name": "string",
"popularity": 0,
"type": "artist",
"uri": "string"
}
"#;
crate::test::assert_deserialized!(Artist, json);
}
#[test]
fn simplified_artist() {
let json = r#"
{
"external_urls": {
"spotify": "string"
},
"href": "string",
"id": "string",
"name": "string",
"type": "artist",
"uri": "string"
}
"#;
crate::test::assert_deserialized!(SimplifiedArtist, json);
}
}