From 298806448db4a4e74306ec648bfc0e43a76c6bc3 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Thu, 20 Dec 2018 23:42:45 +0000 Subject: Split auth and unauth client and created ClientTrait --- src/helix/namespaces/auth.rs | 14 +++++++------- src/helix/namespaces/clips.rs | 10 +++++----- src/helix/namespaces/mod.rs | 17 +++++++++++++++++ src/helix/namespaces/users.rs | 14 +++++++++----- src/helix/namespaces/videos.rs | 2 +- 5 files changed, 39 insertions(+), 18 deletions(-) (limited to 'src/helix/namespaces') diff --git a/src/helix/namespaces/auth.rs b/src/helix/namespaces/auth.rs index 5efc0fe..478c1af 100644 --- a/src/helix/namespaces/auth.rs +++ b/src/helix/namespaces/auth.rs @@ -1,9 +1,9 @@ -use futures::future::Future; use std::collections::BTreeMap; use super::super::models::Credentials; use super::super::Client; const ID_DOMAIN: &'static str = "id.twitch.tv"; -use super::super::Namespace; +use super::Namespace; +use super::super::ClientTrait; pub struct Auth {} type AuthNamespace = Namespace; @@ -34,10 +34,10 @@ pub fn client_credentials(client: Client, secret: &str) ID_DOMAIN + "/oauth2/token"; let mut params = BTreeMap::new(); - params.insert("client_id".to_owned(), client.id().to_owned()); - params.insert("client_secret".to_owned(), secret.to_owned()); - params.insert("grant_type".to_owned(), "client_credentials".to_owned()); - params.insert("scope".to_owned(), "".to_owned()); + params.insert("client_id", client.id()); + params.insert("client_secret", secret); + params.insert("grant_type", "client_credentials"); + params.insert("scope", ""); - ApiRequest::new(url, params, client, Method::POST, None) + ApiRequest::new(url, params, client.clone(), Method::POST, None) } diff --git a/src/helix/namespaces/clips.rs b/src/helix/namespaces/clips.rs index 083e5c4..19293cc 100644 --- a/src/helix/namespaces/clips.rs +++ b/src/helix/namespaces/clips.rs @@ -1,9 +1,10 @@ -use futures::future::Future; use std::collections::BTreeMap; use super::super::models::{DataContainer, PaginationContainer, User, Video, Clip}; use super::super::Client; +use super::super::ClientTrait; +use super::super::RatelimitKey; const API_DOMAIN: &'static str = "api.twitch.tv"; -use super::super::Namespace; +use super::Namespace; pub struct Clips {} type ClipsNamespace = Namespace; @@ -30,10 +31,9 @@ pub fn clip(client: Client, id: &str) { let url = String::from("https://") + - API_DOMAIN + "/helix/clips" + "?id=" + id; + client.domain() + "/helix/clips" + "?id=" + id; let params = BTreeMap::new(); - let limit = client.default_ratelimit(); - ApiRequest::new(url, params, client, Method::GET, Some(limit)) + ApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default)) } diff --git a/src/helix/namespaces/mod.rs b/src/helix/namespaces/mod.rs index d1c44bd..1c0d08e 100644 --- a/src/helix/namespaces/mod.rs +++ b/src/helix/namespaces/mod.rs @@ -1,4 +1,21 @@ +use std::marker::PhantomData; +use super::Client; + pub mod clips; pub mod users; pub mod videos; pub mod auth; + +pub struct Namespace { + client: Client, + _type: PhantomData +} + +impl Namespace { + pub fn new(client: &Client) -> Self { + Namespace { + client: client.clone(), + _type: PhantomData, + } + } +} diff --git a/src/helix/namespaces/users.rs b/src/helix/namespaces/users.rs index c809b95..3e4f1dd 100644 --- a/src/helix/namespaces/users.rs +++ b/src/helix/namespaces/users.rs @@ -3,25 +3,28 @@ use super::super::models::{DataContainer, PaginationContainer, User, Video, Clip use super::super::Client; use std::collections::BTreeMap; const API_DOMAIN: &'static str = "api.twitch.tv"; -use super::super::Namespace; +use super::Namespace; pub struct Users {} type UsersNamespace = Namespace; impl UsersNamespace { + /* pub fn users(self, id: Vec<&str>, login: Vec<&str>) -> impl Future, Error=reqwest::Error> { - use self::users; - users(self.client, id, login) + //use self::users; + //users(self.client, id, login) } + */ } - +/* impl Client { pub fn users(&self) -> UsersNamespace { UsersNamespace::new(self) } } - +*/ +/* pub fn users( client: Client, id: Vec<&str>, @@ -50,3 +53,4 @@ pub fn users( }) .and_then(|json| json) } +*/ diff --git a/src/helix/namespaces/videos.rs b/src/helix/namespaces/videos.rs index ad5ca28..7b8839b 100644 --- a/src/helix/namespaces/videos.rs +++ b/src/helix/namespaces/videos.rs @@ -3,7 +3,7 @@ use super::super::models::{DataContainer, PaginationContainer, User, Video, Clip use super::super::Client; use std::collections::BTreeMap; const API_DOMAIN: &'static str = "api.twitch.tv"; -use super::super::Namespace; +use super::Namespace; pub struct Videos {} type VideosNamespace = Namespace; -- cgit v1.2.3