From 54bcdf63d941dbbd0b3e565259515f013f1ecd13 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Thu, 13 Dec 2018 16:50:33 +0000 Subject: Add clip endpoint --- src/bin/main.rs | 15 ++++++++++++++- src/lib.rs | 22 ++++++++++++++++++++-- src/models.rs | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bin/main.rs b/src/bin/main.rs index f2be7d8..61e16ef 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -12,6 +12,7 @@ fn main() { dotenv::dotenv().unwrap(); let twitch_api = Client::new(&env::var("TWITCH_API").unwrap()); + /* let users = twitch_api .users(vec![], vec!["shroud", "ninja"]) .and_then(|json| { @@ -36,8 +37,20 @@ fn main() { println!("{:?}", err); () }); + */ + let clip = twitch_api + .clip(&"EnergeticApatheticTarsierThisIsSparta") + .and_then(|json| { + println!("{:?}", json); + Ok(json) + }) + .map(|_| ()) + .map_err(|err| { + println!("{:?}", err); + () + }); - tokio::run(users.join(videos).map(|_| ())); + tokio::run(clip); } diff --git a/src/lib.rs b/src/lib.rs index 37c89ca..450ffde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ use reqwest::header; use reqwest::r#async::{Chunk, Decoder, Request, Response}; use reqwest::r#async::Client as ReqwestClient; -use self::models::{DataContainer, PaginationContainer, User, Video}; +use self::models::{DataContainer, PaginationContainer, User, Video, Clip}; const API_DOMAIN: &'static str = "api.twitch.tv"; @@ -103,11 +103,29 @@ impl Client { .get(&url) .send() .map(|mut res| { - println!("{:?}", res); res.json::>() }) .and_then(|json| json); return f; } + + pub fn clip(&self, id: &str) + -> impl Future, Error=reqwest::Error> + { + let url = + String::from("https://") + + API_DOMAIN + "/helix/clips" + "?id=" + id; + + let f = self.create_client() + .get(&url) + .send() + .map(|mut res| { + println!("{:?}", res); + res.json::>() + }) + .and_then(|json| json); + + return f; + } } diff --git a/src/models.rs b/src/models.rs index 52c4781..2b01e7c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -56,3 +56,21 @@ pub struct User { pub view_count: u32, pub email: Option, } + +#[derive(Debug, Deserialize)] +pub struct Clip { + pub id: String, + pub url: String, + pub embed_url: String, + pub broadcaster_id: String, + pub broadcaster_name: String, + pub creator_id: String, + pub creator_name: String, + pub video_id: String, + pub game_id: String, + pub language: String, + pub title: String, + pub created_at: String, + pub thumbnail_url: String, + pub view_count: i32, +} -- cgit v1.2.3