diff options
author | David Blajda <blajda@hotmail.com> | 2018-12-13 16:50:33 +0000 |
---|---|---|
committer | David Blajda <blajda@hotmail.com> | 2018-12-13 16:50:33 +0000 |
commit | 54bcdf63d941dbbd0b3e565259515f013f1ecd13 (patch) | |
tree | a1f74c783ff99744b6852164af5aabd9bd4adb30 | |
parent | 0e41bde5b8fca4451e7e39f9fdd4636f408850bb (diff) |
Add clip endpoint
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/bin/main.rs | 15 | ||||
-rw-r--r-- | src/lib.rs | 22 | ||||
-rw-r--r-- | src/models.rs | 18 |
4 files changed, 53 insertions, 4 deletions
@@ -1,6 +1,6 @@ [package] name = "twitch_api" -version = "0.0.21" +version = "0.0.22" authors = ["David Blajda <blajda@hotmail.com>"] edition = "2018" 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); } @@ -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::<PaginationContainer<Video>>() }) .and_then(|json| json); return f; } + + pub fn clip(&self, id: &str) + -> impl Future<Item=DataContainer<Clip>, 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::<DataContainer<Clip>>() + }) + .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<String>, } + +#[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, +} |