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
macro_rules! expand_media_download {
($i: ident) => {
impl $i {
///Download to the given path the resource specified in the Id
/// MediaQuality is an enum that specifies different image sizes
/// # Examples
/// ```no_run
/// use igdb::client::IGDBClient;
/// use igdb::media_quality::MediaQuality;
/// let client = IGDBClient::new("client_id", "token");
/// let screenshot_client = client.screenshots();
/// screenshot_client.download_by_id(12400, "screen.jpg".to_string(), MediaQuality::ScreenshotHuge,);
/// ```
///
pub async fn download_by_id<S: Into<String>>(
&self,
id: usize,
path: S,
media_quality: MediaQuality,
) -> Result<(), Error> {
use crate::media_helpers::download_resource;
let media = self.get_first_by_id(id).await?;
download_resource(path.into(), media.url.clone(), media_quality).await
}
///Retrieves content in bytes for the given media resource
/// MediaQuality is an enum that specifies different image sizes
/// # Examples
/// ```no_run
/// use igdb::client::IGDBClient;
/// use igdb::media_quality::MediaQuality;
/// let client = IGDBClient::new("client_id", "token");
/// let screenshot_client = client.screenshots();
/// screenshot_client.get_resource_by_id(12400, MediaQuality::ScreenshotHuge,);
/// ```
///
pub async fn get_resource_by_id(
&self,
id: usize,
media_quality: MediaQuality,
) -> Result<Vec<u8>, Error> {
use crate::media_helpers::get_resource;
let media = self.get_first_by_id(id).await?;
get_resource(media.url.clone(), media_quality).await
}
}
};
}