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
use crate::spotify::{Album, Artist, Spotify, SpotifyCollection, SpotifyError, SpotifyObject};
use crate::srequest::RequestMethod;
impl Spotify {
/// Get information on a single aritst: <https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artist>
///
/// Required scope: none
///
/// # Arguments
/// * `artist_id` - The Spotify ID of the artist.
///
pub fn get_artist(&self, artist_id: &str) -> Result<Artist, SpotifyError> {
let url_extension = format!("artists/{}", artist_id);
let response = self.spotify_request(&url_extension, RequestMethod::Get)?; // make request
return Ok(Artist::new(&response)); // format and return result
}
/// Gets information on several artists: <https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-artists>
///
/// Required scope: none
///
/// # Arguments
/// * `artist_ids` - A vector of the Spotify IDs for the artists. Maximum: 50 IDs.
///
pub fn get_several_artists(
&self,
artist_ids: Vec<&str>,
) -> Result<Vec<Artist>, SpotifyError> {
let url_extension = format!("artists/?ids={}", artist_ids.join(",")); // base url with artist ids added
let response = self.spotify_request(&url_extension, RequestMethod::Get)?; // make request
let mut artists = Vec::new(); // create vector to store artists
for artist in response["artists"].members() {
artists.push(Artist::new(&artist)); // format artist and push to vector
}
return Ok(artists); // return vector of artists
}
/// Get artist's albums: <https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-albums>
///
/// Required scope: none
///
/// # Arguments
/// * `artist_id` - The Spotify ID of the artist.
/// * `include_groups` - A list of keywords that will be used to filter the response. If not supplied, all album types will be returned. Valid values: album, single, appears_on, compilation.
/// * `market` - An ISO 3166-1 alpha-2 country code.
/// * `limit` - The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
/// * `offset` - The index of the first item to return. Default: 0 (the first object). Use with limit to get the next set of items.
///
pub fn get_artist_albums(
&self,
artist_id: &str,
include_groups: Option<Vec<&str>>,
limit: Option<u32>,
market: Option<&str>,
offset: Option<u32>,
) -> Result<SpotifyCollection<Album>, SpotifyError> {
let mut url_extension = format!("artists/{}/albums", artist_id); // base url
if include_groups != None || limit != None || market != None || offset != None {
// if any optional parameters are set, add query question mark
url_extension.push_str("?");
}
if let Some(include_groups) = include_groups {
// if include_groups is set, add to url
url_extension.push_str(&format!("&include_groups={}", include_groups.join(",")));
}
if let Some(limit) = limit {
// if limit is set, add to url
url_extension.push_str(&format!("&limit={}", limit));
}
if let Some(market) = market {
// if market is set, add to url
url_extension.push_str(&format!("&market={}", market));
}
if let Some(offset) = offset {
// if offset is set, add to url
url_extension.push_str(&format!("&offset={}", offset));
}
let response = self.spotify_request(&url_extension, RequestMethod::Get)?; // make request
return Ok(SpotifyCollection::<Album>::new(&response)); // format and return result
}
/// Get artist's top tracks: <https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks>
///
/// Required scope: none
///
/// # Arguments
/// * `artist_id` - The Spotify ID of the artist.
/// * `market` - An ISO 3166-1 alpha-2 country code.
///
pub fn get_artist_top_tracks(
&self,
artist_id: &str,
market: &str,
) -> Result<Vec<Artist>, SpotifyError> {
let url_extension = format!("artists/{}/top-tracks?market={}", artist_id, market); // base url
let response = self.spotify_request(&url_extension, RequestMethod::Get)?; // make request
let mut artists = Vec::new(); // create vector to store artists
for artist in response["tracks"].members() {
artists.push(Artist::new(&artist)); // format artist and push to vector
}
return Ok(artists); // return vector of artists
}
/// Get artist's related to specified artist: <https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-related-artists>
///
/// Required scope: none
///
/// # Arguments
/// * `artist_id` - The Spotify ID of the artist.
///
pub fn get_artist_related_artists(
&self,
artist_id: &str,
) -> Result<Vec<Artist>, SpotifyError> {
let url_extension = format!("artists/{}/related-artists", artist_id); // base url
let response = self.spotify_request(&url_extension, RequestMethod::Get)?; // make request
let mut artists = Vec::new(); // create vector to store artists
for artist in response["artists"].members() {
artists.push(Artist::new(&artist)); // format artist and push to vector
}
return Ok(artists); // return vector of artists
}
}