Skip to main content

ytmapi_rs/query/
album.rs

1use super::{PostMethod, PostQuery, Query};
2use crate::auth::AuthToken;
3use crate::common::{AlbumID, YoutubeID};
4use crate::parse::GetAlbum;
5use serde_json::json;
6
7#[derive(Clone)]
8pub struct GetAlbumQuery<'a> {
9    browse_id: AlbumID<'a>,
10}
11impl<A: AuthToken> Query<A> for GetAlbumQuery<'_> {
12    type Output = GetAlbum;
13    type Method = PostMethod;
14}
15impl PostQuery for GetAlbumQuery<'_> {
16    fn header(&self) -> serde_json::Map<String, serde_json::Value> {
17        let serde_json::Value::Object(map) = json!({
18             "browseId" : self.browse_id.get_raw(),
19        }) else {
20            unreachable!("Created a map");
21        };
22        map
23    }
24    fn path(&self) -> &str {
25        "browse"
26    }
27    fn params(&self) -> std::vec::Vec<(&str, std::borrow::Cow<'_, str>)> {
28        vec![]
29    }
30}
31impl<'a> GetAlbumQuery<'_> {
32    pub fn new<T: Into<AlbumID<'a>>>(browse_id: T) -> GetAlbumQuery<'a> {
33        GetAlbumQuery {
34            browse_id: browse_id.into(),
35        }
36    }
37}