summaryrefslogtreecommitdiff
path: root/src/helix/namespaces
diff options
context:
space:
mode:
authorDavid Blajda <blajda@hotmail.com>2018-12-16 21:45:58 +0000
committerDavid Blajda <blajda@hotmail.com>2018-12-16 21:45:58 +0000
commit23ea9413cd0e29eb451df08c5c799d64f56a1342 (patch)
tree226a2bc179e41c675aa0ed34ddc1fda7c55c277a /src/helix/namespaces
parent27267ed98fc839b51ae4621fd1aa230f7f068bdc (diff)
Move endpoints functions into namespaces
Diffstat (limited to 'src/helix/namespaces')
-rw-r--r--src/helix/namespaces/clips.rs42
-rw-r--r--src/helix/namespaces/mod.rs3
-rw-r--r--src/helix/namespaces/users.rs52
-rw-r--r--src/helix/namespaces/videos.rs54
4 files changed, 151 insertions, 0 deletions
diff --git a/src/helix/namespaces/clips.rs b/src/helix/namespaces/clips.rs
new file mode 100644
index 0000000..32793c0
--- /dev/null
+++ b/src/helix/namespaces/clips.rs
@@ -0,0 +1,42 @@
+use futures::future::Future;
+use super::super::models::{DataContainer, PaginationContainer, User, Video, Clip};
+use super::super::Client;
+const API_DOMAIN: &'static str = "api.twitch.tv";
+use super::super::Namespace;
+
+pub struct Clips {}
+type ClipsNamespace = Namespace<Clips>;
+
+impl ClipsNamespace {
+ pub fn clip(self, id: &str) -> impl Future<Item=DataContainer<Clip>, Error=reqwest::Error> {
+ use self::clip;
+ clip(self.client, id)
+ }
+}
+
+impl Client {
+
+ pub fn clips(&self) -> ClipsNamespace {
+ ClipsNamespace::new(self)
+ }
+}
+
+pub fn clip(client: Client, id: &str)
+ -> impl Future<Item=DataContainer<Clip>, Error=reqwest::Error>
+{
+ let url =
+ String::from("https://") +
+ API_DOMAIN + "/helix/clips" + "?id=" + id;
+
+
+ let request = client.client().get(&url);
+ let request = client.apply_standard_headers(request);
+
+ request
+ .send()
+ .map(|mut res| {
+ println!("{:?}", res);
+ res.json::<DataContainer<Clip>>()
+ })
+ .and_then(|json| json)
+}
diff --git a/src/helix/namespaces/mod.rs b/src/helix/namespaces/mod.rs
new file mode 100644
index 0000000..ad73aa3
--- /dev/null
+++ b/src/helix/namespaces/mod.rs
@@ -0,0 +1,3 @@
+pub mod clips;
+pub mod users;
+pub mod videos;
diff --git a/src/helix/namespaces/users.rs b/src/helix/namespaces/users.rs
new file mode 100644
index 0000000..c809b95
--- /dev/null
+++ b/src/helix/namespaces/users.rs
@@ -0,0 +1,52 @@
+use futures::future::Future;
+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;
+
+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)
+ }
+}
+
+impl Client {
+
+ pub fn users(&self) -> UsersNamespace {
+ UsersNamespace::new(self)
+ }
+}
+
+pub fn users(
+ client: Client,
+ id: Vec<&str>,
+ login: Vec<&str>,
+ ) -> impl Future<Item = DataContainer<User>, Error = reqwest::Error> {
+ let url =
+ String::from("https://") + &String::from(API_DOMAIN) + &String::from("/helix/users");
+
+ let mut params = BTreeMap::new();
+ for i in id {
+ params.insert("id", i);
+ }
+
+ for log in login {
+ params.insert("login", log);
+ }
+
+ let request = client.client().get(&url);
+ let request = client.apply_standard_headers(request);
+ let request = request.query(&params);
+
+ request
+ .send()
+ .map(|mut res| {
+ res.json::<DataContainer<User>>()
+ })
+ .and_then(|json| json)
+}
diff --git a/src/helix/namespaces/videos.rs b/src/helix/namespaces/videos.rs
new file mode 100644
index 0000000..ad5ca28
--- /dev/null
+++ b/src/helix/namespaces/videos.rs
@@ -0,0 +1,54 @@
+use futures::future::Future;
+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;
+
+pub struct Videos {}
+type VideosNamespace = Namespace<Videos>;
+
+impl VideosNamespace {
+ /*
+ pub fn videos(self, video_id) -> impl Future<Item=DataContainer<User>, Error=reqwest::Error> {
+ use self::videos;
+ users(self.client, id, login)
+ }
+ */
+}
+
+impl Client {
+
+ pub fn videos(&self) -> VideosNamespace {
+ VideosNamespace::new(self)
+ }
+}
+
+/*
+pub fn videos(
+ client: Client,
+ video_id: Option<Vec<&str>>,
+ user_id: Option<&str>,
+ game_id: Option<&str>,
+) -> impl Future<Item = PaginationContainer<Video>, Error = reqwest::Error> {
+ let mut url =
+ String::from("https://") + &String::from(API_DOMAIN) + &String::from("/helix/videos");
+
+ let mut params = BTreeMap::new();
+ for user in user_id {
+ params.insert("user_id", user);
+ }
+
+ let request = client.client().get(&url);
+ let request = client.apply_standard_headers(request);
+ let request = request.query(&params);
+
+ request
+ .send()
+ .map(|mut res| {
+ res.json::<PaginationContainer<Video>>()
+ })
+ .and_then(|json| json)
+
+}
+*/