1use crate::auth::{AuthToken, raw_query_get, raw_query_post};
35use crate::parse::ParseFrom;
36use crate::{RawResult, Result};
37use private::Sealed;
38use std::borrow::Cow;
39use std::fmt::Debug;
40use std::future::Future;
41
42pub mod album;
43#[doc(inline)]
44pub use album::GetAlbumQuery;
45pub mod artist;
46#[doc(inline)]
47pub use artist::{
48 GetArtistAlbumsQuery, GetArtistQuery, SubscribeArtistQuery, UnsubscribeArtistsQuery,
49};
50pub mod continuations;
51#[doc(inline)]
52pub use continuations::GetContinuationsQuery;
53pub mod history;
54#[doc(inline)]
55pub use history::{AddHistoryItemQuery, GetHistoryQuery, RemoveHistoryItemsQuery};
56pub mod library;
57#[doc(inline)]
58pub use library::{
59 EditSongLibraryStatusQuery, GetLibraryAlbumsQuery, GetLibraryArtistSubscriptionsQuery,
60 GetLibraryArtistsQuery, GetLibraryChannelsQuery, GetLibraryPlaylistsQuery,
61 GetLibraryPodcastsQuery, GetLibrarySongsQuery,
62};
63pub mod playlist;
64#[doc(inline)]
65pub use playlist::{
66 AddPlaylistItemsQuery, CreatePlaylistQuery, DeletePlaylistQuery, EditPlaylistQuery,
67 GetPlaylistDetailsQuery, GetPlaylistTracksQuery, GetWatchPlaylistQuery,
68 RemovePlaylistItemsQuery,
69};
70pub mod podcasts;
71#[doc(inline)]
72pub use podcasts::{
73 GetChannelEpisodesQuery, GetChannelQuery, GetEpisodeQuery, GetNewEpisodesQuery, GetPodcastQuery,
74};
75pub mod rate;
76#[doc(inline)]
77pub use rate::{RatePlaylistQuery, RateSongQuery};
78pub mod recommendations;
79#[doc(inline)]
80pub use recommendations::{
81 GetMoodCategoriesQuery, GetMoodPlaylistsQuery, GetTasteProfileQuery, SetTasteProfileQuery,
82};
83pub mod search;
84#[doc(inline)]
85pub use search::{GetSearchSuggestionsQuery, SearchQuery};
86pub mod song;
87#[doc(inline)]
88pub use song::{GetLyricsIDQuery, GetLyricsQuery, GetSongTrackingUrlQuery};
89pub mod upload;
90#[doc(inline)]
91pub use upload::{
92 DeleteUploadEntityQuery, GetLibraryUploadAlbumQuery, GetLibraryUploadAlbumsQuery,
93 GetLibraryUploadArtistQuery, GetLibraryUploadArtistsQuery, GetLibraryUploadSongsQuery,
94};
95pub mod user;
96#[doc(inline)]
97pub use user::{GetUserPlaylistsQuery, GetUserQuery, GetUserVideosQuery};
98
99mod private {
100 pub trait Sealed {}
101}
102
103pub trait Query<A: AuthToken>: Sized {
107 type Output: ParseFrom<Self>;
108 type Method: QueryMethod<Self, A>;
109}
110
111pub trait PostQuery {
113 fn header(&self) -> serde_json::Map<String, serde_json::Value>;
114 fn params(&self) -> Vec<(&str, Cow<'_, str>)>;
115 fn path(&self) -> &str;
116}
117pub trait GetQuery {
119 fn url(&self) -> &str;
120 fn params(&self) -> Vec<(&str, Cow<'_, str>)>;
121}
122
123pub struct GetMethod;
125pub struct PostMethod;
127
128#[allow(async_fn_in_trait)]
134pub trait QueryMethod<Q, A>: Sealed
135where
136 A: AuthToken,
137{
138 async fn call<'a>(
139 query: &'a Q,
140 client: &crate::client::Client,
141 tok: &A,
142 ) -> Result<RawResult<'a, Q, A>>;
143}
144
145impl Sealed for GetMethod {}
146impl<Q, A> QueryMethod<Q, A> for GetMethod
147where
148 Q: GetQuery,
149 A: AuthToken,
150{
151 fn call<'a>(
152 query: &'a Q,
153 client: &crate::client::Client,
154 tok: &A,
155 ) -> impl Future<Output = Result<RawResult<'a, Q, A>>>
156 where
157 Self: Sized,
158 {
159 raw_query_get(tok, client, query)
160 }
161}
162
163impl Sealed for PostMethod {}
164impl<Q, A> QueryMethod<Q, A> for PostMethod
165where
166 Q: PostQuery,
167 A: AuthToken,
168{
169 fn call<'a>(
170 query: &'a Q,
171 client: &crate::client::Client,
172 tok: &A,
173 ) -> impl Future<Output = Result<RawResult<'a, Q, A>>>
174 where
175 Self: Sized,
176 {
177 raw_query_post(query, tok, client)
178 }
179}