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
use crate::client::endpoints::TargetAPI;
use crate::client::response::{Paginated, Wrapped};
use crate::client::{EndpointArtist, Error, RequestParameters};
use crate::mc::artist::Artist;
use std::collections::HashMap;
use std::fmt::Display;
impl<ClientAuthState> EndpointArtist<'_, ClientAuthState> {
/// Get all artists.
///
/// Use the optional parameters to alter the pagination or search term.
///
/// Example
/// ```rust
/// use bombay::client::Client;
///
/// let mc = Client::default(); // Without authentication.
/// let all_artists_res = mc.artist().get_all(None);
///
/// if let Ok(all_artists) = all_artists_res {
/// println!("There are {} Monstercat artists.", all_artists.total);
/// }
/// ```
///
/// Example URL: <https://player.monstercat.app/api/artists>
pub fn get_all(
&self,
parameters: Option<RequestParameters>,
) -> Result<Paginated<Artist>, Error> {
self.client
.get::<Wrapped<Paginated<Artist>>>(TargetAPI::Player, "/artists", parameters)?
.remove("Artists")
.ok_or(Error::NotFound("all artists"))
}
/// Get artist by name uri, which is a slight variation on the name depending on the characters involved.
///
/// Example
/// ```rust
/// use bombay::client::Client;
///
/// let mc = Client::default(); // Without authentication.
/// let ace_aura_res = mc.artist().get_by_name_uri("ace-aura");
///
/// if let Ok(ace_aura) = ace_aura_res {
/// println!("Found {}.", ace_aura.name);
/// }
/// ```
///
/// Example URL: <https://player.monstercat.app/api/artist/ace-aura>
pub fn get_by_name_uri(
&self,
artist_name_uri: impl AsRef<str> + Display,
) -> Result<Artist, Error> {
self.client.get::<Artist>(
TargetAPI::Player,
&format!("/artist/{artist_name_uri}"),
None::<HashMap<String, String>>,
)
}
/// Get latest artists.
///
/// Use the optional parameters to alter the pagination or search term.
///
/// Example
/// ```rust
/// use bombay::client::Client;
///
/// let mc = Client::default(); // Without authentication.
/// let latest_artists_res = mc.artist().get_latest(None);
///
/// if let Ok(artists_resp) = latest_artists_res {
/// if let Some(latest_artists) = artists_resp.data {
/// if let Some(latest_artist) = latest_artists.get(0) {
/// println!("Welcome {}!", latest_artist.name);
/// }
/// }
/// }
/// ```
///
/// Example URL: <https://player.monstercat.app/api/latest-artists>
pub fn get_latest(
&self,
parameters: Option<RequestParameters>,
) -> Result<Paginated<Artist>, Error> {
self.client
.get::<Wrapped<Paginated<Artist>>>(TargetAPI::Player, "/latest-artists", parameters)?
.remove("LatestArtists")
.ok_or(Error::NotFound("latest artists"))
}
/// Get artist's profile photo.
///
/// Example
/// ```rust
/// use bombay::client::Client;
///
/// let mc = Client::default(); // Without authentication.
/// let mut reader = mc.artist().get_photo("lanidaye").expect("Could not get photo.");
///
/// let _dir = std::fs::create_dir_all("downloads").unwrap();
/// let mut file_out = std::fs::File::create("downloads/lanidaye.jpeg").expect("Could not create file.");
/// std::io::copy(&mut reader, &mut file_out).expect("Could not save photo.");
/// ```
pub fn get_photo(
&self,
artist_name_uri: impl AsRef<str> + Display,
) -> Result<Box<dyn std::io::Read + Send + Sync>, Error> {
self.client.get_reader(
TargetAPI::WWW,
&format!("artist/{artist_name_uri}/photo"),
None::<HashMap<String, String>>,
)
}
}