ytmapi_rs/
auth.rs

1//! Available authorisation tokens.
2use self::private::Sealed;
3use crate::client::Client;
4use crate::error::Result;
5use crate::parse::ProcessedResult;
6use crate::query::{GetQuery, PostQuery};
7use crate::{process::RawResult, query::Query};
8pub use browser::BrowserToken;
9pub use oauth::{OAuthToken, OAuthTokenGenerator};
10
11pub mod browser;
12pub mod oauth;
13
14mod private {
15    pub trait Sealed {}
16}
17
18/// An authentication token into Youtube Music that can be used to query the
19/// API. Currently sealed due to use of async, although this could become open
20/// for implementation in future.
21// Allow async_fn_in_trait required, as trait currently sealed.
22#[allow(async_fn_in_trait)]
23pub trait AuthToken: Sized + Sealed {
24    // TODO: Continuations - as Stream?
25    /// Run a post query that returns a raw json response.
26    async fn raw_query_post<'a, Q: PostQuery + Query<Self>>(
27        &self,
28        client: &Client,
29        query: &'a Q,
30    ) -> Result<RawResult<'a, Q, Self>>;
31    /// Run a get query that returns a raw json response.
32    async fn raw_query_get<'a, Q: GetQuery + Query<Self>>(
33        &self,
34        client: &Client,
35        query: &'a Q,
36    ) -> Result<RawResult<'a, Q, Self>>;
37    /// Process the result, by deserializing into JSON and checking for errors.
38    fn deserialize_json<Q: Query<Self>>(raw: RawResult<Q, Self>) -> Result<ProcessedResult<Q>>;
39}