From 96715ceb58b24ee7220d98e421701daa550f44db Mon Sep 17 00:00:00 2001 From: David Blajda Date: Sun, 3 Feb 2019 22:30:15 +0000 Subject: Add Helix and Kraken scopes. Client Config and allow injecting of responses --- src/helix/mod.rs | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src/helix/mod.rs') diff --git a/src/helix/mod.rs b/src/helix/mod.rs index 53a4ffb..da24aa4 100644 --- a/src/helix/mod.rs +++ b/src/helix/mod.rs @@ -1,24 +1,12 @@ -pub mod models; -pub mod namespaces; - use crate::client::Client as GenericClient; -use crate::client::Version; +use crate::client::{Version, ClientConfig}; use crate::client::ClientTrait; -/* -#[derive(PartialEq, Hash, Eq, Clone)] -pub enum Scope { - AnalyticsReadExtensions, - AnalyticsReadGames, - BitsRead, - ClipsEdit, - UserEdit, - UserEditBroadcast, - UserReadBroadcast, - UserReadEmail, -} -*/ -use crate::client::Scope; +use crate::client::{HelixScope, Scope}; + +pub mod models; +pub mod namespaces; + #[derive(Clone)] pub struct Client { @@ -27,14 +15,32 @@ pub struct Client { impl Client { pub fn new(id: &str) -> Client { + let config = ClientConfig::default(); Client { - inner: GenericClient::new(id, Version::Helix) + inner: GenericClient::new(id, config, Version::Helix) + } + } + + pub fn new_with_config(id: &str, config: ClientConfig) -> Client { + Client { + inner: GenericClient::new(id, config, Version::Helix) } } pub fn authenticate(self, secret: &str) -> AuthClientBuilder { AuthClientBuilder::new(self, secret) } + + pub fn id<'a>(&'a self) -> &'a str { &self.inner.id() } + pub fn domain<'a>(&'a self) -> &'a str { &self.inner.domain() } + pub fn auth_domain<'a>(&'a self) -> &'a str { &self.inner.auth_domain() } + pub fn authenticated(&self) -> bool { self.inner.authenticated() } + + pub fn scopes(&self) -> Vec { + self.inner.scopes().into_iter().filter_map(|item| { + if let Scope::Helix(scope) = item { Some(scope) } else { None } + }).collect() + } } use crate::client::AuthClientBuilder as GenericAuthClientBuilder; @@ -57,15 +63,15 @@ impl AuthClientBuilder { } } - pub fn scope(self, scope: Scope) -> AuthClientBuilder { + pub fn scope(self, scope: HelixScope) -> AuthClientBuilder { AuthClientBuilder { - inner: self.inner.scope(scope) + inner: self.inner.scope(Scope::Helix(scope)) } } - pub fn scopes(self, scopes: Vec) -> AuthClientBuilder { + pub fn scopes(self, scopes: Vec) -> AuthClientBuilder { AuthClientBuilder { - inner: self.inner.scopes(scopes) + inner: self.inner.scopes(scopes.into_iter().map(|e| Scope::Helix(e)).collect()) } } -- cgit v1.2.3