summaryrefslogtreecommitdiff
path: root/src/helix/namespaces
diff options
context:
space:
mode:
authorDavid Blajda <blajda@hotmail.com>2018-12-20 23:42:45 +0000
committerDavid Blajda <blajda@hotmail.com>2018-12-20 23:42:45 +0000
commit298806448db4a4e74306ec648bfc0e43a76c6bc3 (patch)
tree1cdd90df0d65a513ad94588dae7621b03a906b3e /src/helix/namespaces
parent2bae9a4e8d8b77f8a99df6829547a60f883632a3 (diff)
Split auth and unauth client and created ClientTrait
Diffstat (limited to 'src/helix/namespaces')
-rw-r--r--src/helix/namespaces/auth.rs14
-rw-r--r--src/helix/namespaces/clips.rs10
-rw-r--r--src/helix/namespaces/mod.rs17
-rw-r--r--src/helix/namespaces/users.rs14
-rw-r--r--src/helix/namespaces/videos.rs2
5 files changed, 39 insertions, 18 deletions
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<Auth>;
@@ -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<Clips>;
@@ -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<T> {
+ client: Client,
+ _type: PhantomData<T>
+}
+
+impl<T> Namespace<T> {
+ 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<Users>;
impl UsersNamespace {
+ /*
pub fn users(self, id: Vec<&str>, login: Vec<&str>) -> impl Future<Item=DataContainer<User>, 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<Videos>;