Skip to main content

igdb_rs/
media_macros.rs

1macro_rules! expand_media_download {
2    ($i: ident) => {
3        impl $i {
4            ///Download to the given path the resource specified in the Id
5            /// MediaQuality is an enum that specifies different image sizes
6            /// # Examples
7            /// ```no_run
8            /// use igdb_rs::client::IGDBClient;
9            /// use igdb_rs::media_quality::MediaQuality;
10            /// let client = IGDBClient::new("key");
11            /// let screenshot_client = client.screenshots();
12            /// screenshot_client.download_by_id(12400, "screen.jpg".to_string(), MediaQuality::ScreenshotHuge,);
13            /// ```
14            ///
15            pub async fn download_by_id<S: Into<String>>(
16                &self,
17                id: usize,
18                path: S,
19                media_quality: MediaQuality,
20            ) -> Result<(), Error> {
21                use crate::media_helpers::download_resource;
22
23                let media = self.get_first_by_id(id).await?;
24                download_resource(path.into(), media.url.clone(), media_quality).await
25            }
26            ///Retrieves content in bytes for the given media resource
27            /// MediaQuality is an enum that specifies different image sizes
28            /// # Examples
29            /// ```no_run
30            /// use igdb_rs::client::IGDBClient;
31            /// use igdb_rs::media_quality::MediaQuality;
32            /// let client = IGDBClient::new("key");
33            /// let screenshot_client = client.screenshots();
34            /// screenshot_client.get_resource_by_id(12400, MediaQuality::ScreenshotHuge,);
35            /// ```
36            ///
37            pub async fn get_resource_by_id(
38                &self,
39                id: usize,
40                media_quality: MediaQuality,
41            ) -> Result<Vec<u8>, Error> {
42                use crate::media_helpers::get_resource;
43
44                let media = self.get_first_by_id(id).await?;
45                get_resource(media.url.clone(), media_quality).await
46            }
47        }
48    };
49}