diff options
author | David Blajda <blajda@hotmail.com> | 2018-12-16 21:45:58 +0000 |
---|---|---|
committer | David Blajda <blajda@hotmail.com> | 2018-12-16 21:45:58 +0000 |
commit | 23ea9413cd0e29eb451df08c5c799d64f56a1342 (patch) | |
tree | 226a2bc179e41c675aa0ed34ddc1fda7c55c277a /src/helix/mod.rs | |
parent | 27267ed98fc839b51ae4621fd1aa230f7f068bdc (diff) |
Move endpoints functions into namespaces
Diffstat (limited to 'src/helix/mod.rs')
-rw-r--r-- | src/helix/mod.rs | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/helix/mod.rs b/src/helix/mod.rs index fe873dd..650c4b0 100644 --- a/src/helix/mod.rs +++ b/src/helix/mod.rs @@ -4,9 +4,8 @@ use reqwest::r#async::Client as ReqwestClient; pub use super::types; use std::marker::PhantomData; - -pub mod endpoints; pub mod models; +pub mod namespaces; use std::collections::HashSet; @@ -18,10 +17,6 @@ pub trait UsersEndpoint {} pub trait VideosEndpoint {} -pub trait ClipsEndpointTrait { - fn clip(&self, id: &str) -> EndPointResult<DataContainer<Clip>>; -} - pub trait AuthEndpoint {} pub struct Namespace<T> { @@ -38,10 +33,6 @@ impl<T> Namespace<T> { } } -pub struct Clips {} - -type ClipsNamespace = Namespace<Clips>; - #[derive(Clone)] pub struct Client { inner: Arc<ClientRef>, @@ -79,13 +70,6 @@ impl Client { }) } } -} - - -use reqwest::r#async::{RequestBuilder}; -use reqwest::header; - -impl Client { pub fn id(&self) -> &str { &self.inner.id @@ -95,6 +79,30 @@ impl Client { &self.inner.client } + pub fn authenticated(&self) -> bool { + let mut_data = self.inner.inner.lock().unwrap(); + mut_data.token.is_some() + } + + /* + pub fn scopes(&self) -> Vec<Scope> { + let mut_data = self.inner.inner.lock().unwrap(); + (&mut_data.scopes).into_iter().to_owned().collect() + } + */ + + pub fn authenticate(self) -> AuthClientBuilder { + AuthClientBuilder::new(self) + } + + pub fn deauthenticate(self) -> Client { + let mut_data = self.inner.inner.lock().unwrap(); + match &mut_data.previous { + Some(old_client) => old_client.clone(), + None => self.clone() + } + } + fn apply_standard_headers(&self, request: RequestBuilder) -> RequestBuilder { @@ -103,37 +111,27 @@ impl Client { } } -impl Client { - - pub fn clips(&self) -> ClipsNamespace { - ClipsNamespace::new(self) - } -} +use reqwest::r#async::{RequestBuilder}; +use reqwest::header; -impl ClipsNamespace { - pub fn clip(self, id: &str) -> impl Future<Item=DataContainer<Clip>, Error=reqwest::Error> { - use self::endpoints::clip; - clip(self.client, id) - } -} pub struct AuthClientBuilder { scopes: HashSet<Scope>, - secret: String, + secret: Option<String>, + token: Option<String>, client: Client, /*If the user supplies a token, * then we can skip fetching it from the server and are authenticated */ - token: Option<String>, } impl AuthClientBuilder { - pub fn new(client: Client, secret: &str) -> AuthClientBuilder { + pub fn new(client: Client) -> AuthClientBuilder { AuthClientBuilder { scopes: HashSet::new(), - secret: secret.to_owned(), client: client, + secret: None, token: None, } } @@ -164,7 +162,7 @@ impl AuthClientBuilder { } -#[derive(PartialEq, Hash, Eq)] +#[derive(PartialEq, Hash, Eq, Clone)] pub enum Scope { AnalyticsReadExtensions, AnalyticsReadGames, |