use crate::auth::{raw_query_get, raw_query_post, AuthToken};
use crate::parse::ParseFrom;
use crate::{RawResult, Result};
use private::Sealed;
use std::borrow::Cow;
use std::fmt::Debug;
use std::future::Future;
pub mod album;
#[doc(inline)]
pub use album::GetAlbumQuery;
pub mod artist;
#[doc(inline)]
pub use artist::{
GetArtistAlbumsQuery, GetArtistQuery, SubscribeArtistQuery, UnsubscribeArtistsQuery,
};
pub mod continuations;
#[doc(inline)]
pub use continuations::GetContinuationsQuery;
pub mod history;
#[doc(inline)]
pub use history::{AddHistoryItemQuery, GetHistoryQuery, RemoveHistoryItemsQuery};
pub mod library;
#[doc(inline)]
pub use library::{
EditSongLibraryStatusQuery, GetLibraryAlbumsQuery, GetLibraryArtistSubscriptionsQuery,
GetLibraryArtistsQuery, GetLibraryChannelsQuery, GetLibraryPlaylistsQuery,
GetLibraryPodcastsQuery, GetLibrarySongsQuery,
};
pub mod playlist;
#[doc(inline)]
pub use playlist::{
AddPlaylistItemsQuery, CreatePlaylistQuery, DeletePlaylistQuery, EditPlaylistQuery,
GetPlaylistDetailsQuery, GetPlaylistTracksQuery, GetWatchPlaylistQuery,
RemovePlaylistItemsQuery,
};
pub mod podcasts;
#[doc(inline)]
pub use podcasts::{
GetChannelEpisodesQuery, GetChannelQuery, GetEpisodeQuery, GetNewEpisodesQuery, GetPodcastQuery,
};
pub mod rate;
#[doc(inline)]
pub use rate::{RatePlaylistQuery, RateSongQuery};
pub mod recommendations;
#[doc(inline)]
pub use recommendations::{
GetMoodCategoriesQuery, GetMoodPlaylistsQuery, GetTasteProfileQuery, SetTasteProfileQuery,
};
pub mod search;
#[doc(inline)]
pub use search::{GetSearchSuggestionsQuery, SearchQuery};
pub mod song;
#[doc(inline)]
pub use song::{GetLyricsIDQuery, GetLyricsQuery, GetSongTrackingUrlQuery};
pub mod upload;
#[doc(inline)]
pub use upload::{
DeleteUploadEntityQuery, GetLibraryUploadAlbumQuery, GetLibraryUploadAlbumsQuery,
GetLibraryUploadArtistQuery, GetLibraryUploadArtistsQuery, GetLibraryUploadSongsQuery,
};
pub mod user;
#[doc(inline)]
pub use user::{GetUserPlaylistsQuery, GetUserQuery, GetUserVideosQuery};
mod private {
pub trait Sealed {}
}
pub trait Query<A: AuthToken>: Sized {
type Output: ParseFrom<Self>;
type Method: QueryMethod<Self, A>;
}
pub trait PostQuery {
fn header(&self) -> serde_json::Map<String, serde_json::Value>;
fn params(&self) -> Vec<(&str, Cow<'_, str>)>;
fn path(&self) -> &str;
}
pub trait GetQuery {
fn url(&self) -> &str;
fn params(&self) -> Vec<(&str, Cow<'_, str>)>;
}
pub struct GetMethod;
pub struct PostMethod;
#[allow(async_fn_in_trait)]
pub trait QueryMethod<Q, A>: Sealed
where
A: AuthToken,
{
async fn call<'a>(
query: &'a Q,
client: &crate::client::Client,
tok: &A,
) -> Result<RawResult<'a, Q, A>>;
}
impl Sealed for GetMethod {}
impl<Q, A> QueryMethod<Q, A> for GetMethod
where
Q: GetQuery,
A: AuthToken,
{
fn call<'a>(
query: &'a Q,
client: &crate::client::Client,
tok: &A,
) -> impl Future<Output = Result<RawResult<'a, Q, A>>>
where
Self: Sized,
{
raw_query_get(tok, client, query)
}
}
impl Sealed for PostMethod {}
impl<Q, A> QueryMethod<Q, A> for PostMethod
where
Q: PostQuery,
A: AuthToken,
{
fn call<'a>(
query: &'a Q,
client: &crate::client::Client,
tok: &A,
) -> impl Future<Output = Result<RawResult<'a, Q, A>>>
where
Self: Sized,
{
raw_query_post(query, tok, client)
}
}