summaryrefslogtreecommitdiff
path: root/src/kraken
diff options
context:
space:
mode:
authorDavid Blajda <blajda@hotmail.com>2018-12-13 20:56:55 +0000
committerDavid Blajda <blajda@hotmail.com>2018-12-13 20:56:55 +0000
commit8615cc2f030240ba2982dba893fe63f11a0c8a88 (patch)
tree30c7103625323404696331c2384130ce06f8bc96 /src/kraken
parent54bcdf63d941dbbd0b3e565259515f013f1ecd13 (diff)
Restructure project and included kraken endpoint
Diffstat (limited to 'src/kraken')
-rw-r--r--src/kraken/endpoints.rs20
-rw-r--r--src/kraken/mod.rs33
-rw-r--r--src/kraken/models.rs44
3 files changed, 97 insertions, 0 deletions
diff --git a/src/kraken/endpoints.rs b/src/kraken/endpoints.rs
new file mode 100644
index 0000000..2dbc8d1
--- /dev/null
+++ b/src/kraken/endpoints.rs
@@ -0,0 +1,20 @@
+use futures::Future;
+use super::models::Clip;
+use super::Client;
+
+use super::API_DOMAIN;
+
+impl Client {
+ pub fn clip(&self, id: &str)
+ -> impl Future<Item=Clip, Error=reqwest::Error>
+ {
+ let url = String::from("https://") + API_DOMAIN + "/kraken/clips/" + id;
+ let client = self.create_reqwest_client();
+
+ client
+ .get(&url)
+ .send()
+ .map(|mut res| res.json::<Clip>())
+ .and_then(|json| json)
+ }
+}
diff --git a/src/kraken/mod.rs b/src/kraken/mod.rs
new file mode 100644
index 0000000..2015781
--- /dev/null
+++ b/src/kraken/mod.rs
@@ -0,0 +1,33 @@
+use reqwest::header;
+use reqwest::r#async::{Chunk, Decoder, Request, Response};
+use reqwest::r#async::Client as ReqwestClient;
+
+mod endpoints;
+mod models;
+
+const ACCEPT: &str = "application/vnd.twitchtv.v5+json";
+pub const API_DOMAIN: &str = "api.twitch.tv";
+
+pub struct Client {
+ id: String,
+}
+
+impl Client {
+ pub fn new(id: &str) -> Client {
+ Client {
+ id: id.to_owned(),
+ }
+ }
+
+ fn create_reqwest_client(&self) -> ReqwestClient {
+ let mut headers = header::HeaderMap::new();
+ let auth_key = &self.id;
+ let client_header = header::HeaderValue::from_str(auth_key).unwrap();
+ let accept_header = header::HeaderValue::from_str(ACCEPT).unwrap();
+ headers.insert("Client-ID", client_header);
+ headers.insert("Accept", accept_header);
+
+ let client = ReqwestClient::builder().default_headers(headers).build().unwrap();
+ client
+ }
+}
diff --git a/src/kraken/models.rs b/src/kraken/models.rs
new file mode 100644
index 0000000..13c524c
--- /dev/null
+++ b/src/kraken/models.rs
@@ -0,0 +1,44 @@
+extern crate serde_json;
+extern crate chrono;
+
+#[derive(Debug, Deserialize)]
+pub struct Clip {
+ pub slug: String,
+ pub tracking_id: String,
+ pub url: String,
+ pub embed_url: String,
+ pub embed_html: String,
+ pub broadcaster: UserData,
+ pub curator: UserData,
+ pub vod: Vod,
+ pub game: String,
+ pub language: String,
+ pub title: String,
+ pub views: i32,
+ pub duration: f32,
+ pub created_at: String,
+ pub thumbnails: Thumbnails,
+}
+
+
+#[derive(Debug, Deserialize)]
+pub struct Thumbnails {
+ pub medium: String,
+ pub small: String,
+ pub tiny: String,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct UserData {
+ pub id: String,
+ pub name: String,
+ pub display_name: String,
+ pub channel_url: String,
+ pub logo: String,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct Vod {
+ pub id: String,
+ pub url: String,
+}