From 23ea9413cd0e29eb451df08c5c799d64f56a1342 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Sun, 16 Dec 2018 21:45:58 +0000 Subject: Move endpoints functions into namespaces --- src/helix/namespaces/users.rs | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/helix/namespaces/users.rs (limited to 'src/helix/namespaces/users.rs') 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; + +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) + } +} + +impl Client { + + pub fn users(&self) -> UsersNamespace { + UsersNamespace::new(self) + } +} + +pub fn users( + client: Client, + id: Vec<&str>, + login: Vec<&str>, + ) -> impl Future, 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(¶ms); + + request + .send() + .map(|mut res| { + res.json::>() + }) + .and_then(|json| json) +} -- cgit v1.2.3