From 678e3d3f28cb8594204dc5e2b7597ae66a4582c7 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Thu, 27 Dec 2018 22:03:23 +0000 Subject: Use Id types for endpoints and implement kraken headers --- src/helix/namespaces/videos.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/helix/namespaces/videos.rs') diff --git a/src/helix/namespaces/videos.rs b/src/helix/namespaces/videos.rs index a8021f3..75b702e 100644 --- a/src/helix/namespaces/videos.rs +++ b/src/helix/namespaces/videos.rs @@ -1,29 +1,25 @@ -use super::super::models::{PaginationContainer, Video}; -use super::super::Client; -use super::Namespace; - -use crate::client::{ClientTrait, RatelimitKey, IterableApiRequest}; -use std::collections::BTreeMap; -use reqwest::Method; +use super::*; +use super::models::{PaginationContainer, Video}; +use crate::types::{UserId, GameId, VideoId}; pub struct Videos {} type VideosNamespace = Namespace; impl VideosNamespace { - pub fn by_id(self, ids: Vec<&str>) + pub fn by_id(self, ids: Vec<&VideoId>) -> IterableApiRequest> { use self::by_id; by_id(self.client, ids) } - pub fn by_user(self, user_id: &str) + pub fn by_user(self, user_id: &UserId) -> IterableApiRequest> { use self::by_user; by_user(self.client, user_id) } - pub fn for_game(self, game_id: &str) + pub fn for_game(self, game_id: &GameId) -> IterableApiRequest> { use self::for_game; for_game(self.client, game_id) @@ -37,7 +33,7 @@ impl Client { } } -pub fn by_id(client: Client, ids: Vec<&str>) +pub fn by_id(client: Client, ids: Vec<&VideoId>) -> IterableApiRequest> { let client = client.inner; let url = @@ -45,34 +41,34 @@ pub fn by_id(client: Client, ids: Vec<&str>) let mut params = BTreeMap::new(); for id in ids { - params.insert("id", id); + params.insert("id", id.as_ref()); } IterableApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default)) } -pub fn by_user(client: Client, user_id: &str) +pub fn by_user(client: Client, user_id: &UserId) -> IterableApiRequest> { let client = client.inner; let url = String::from("https://") + client.domain() + &String::from("/helix/videos"); let mut params = BTreeMap::new(); - params.insert("user_id", user_id); + params.insert("user_id", user_id.as_ref()); IterableApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default)) } -pub fn for_game(client: Client, game_id: &str) +pub fn for_game(client: Client, game_id: &GameId) -> IterableApiRequest> { let client = client.inner; let url = String::from("https://") + client.domain() + &String::from("/helix/videos"); let mut params = BTreeMap::new(); - params.insert("game_id", game_id); + params.insert("game_id", game_id.as_ref()); IterableApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default)) -- cgit v1.2.3