extern crate serde_json; extern crate chrono; use url::Url; use chrono::{DateTime, Utc}; use crate::types::{UserId, VideoId, ChannelId}; use crate::client::PaginationTrait; #[derive(Debug, Deserialize)] pub struct DataContainer { pub data: Vec } impl PaginationTrait for DataContainer { fn cursor<'a>(&'a self) -> Option<&'a str> { None } } impl PaginationTrait for PaginationContainer { fn cursor<'a>(&'a self) -> Option<&'a str> { match self.pagination.as_ref() { Some(cursor) => { match cursor.cursor.as_ref() { Some(cursor) => Some(cursor), None => None, } }, None => None } } } impl PaginationTrait for Credentials { fn cursor<'a>(&'a self) -> Option<&'a str> { None } } #[derive(Debug, Deserialize)] pub struct PaginationContainer { pub data: Vec, pub pagination: Option } #[derive(Debug, Deserialize)] pub struct Cursor { pub cursor: Option } #[derive(Debug, Deserialize)] pub struct Video { pub id: VideoId, pub user_id: UserId, pub user_name: String, pub title: String, pub description: String, pub created_at: DateTime, pub published_at: DateTime, #[serde(with = "url_serde")] pub url: Url, /*FIXME: Serde will attempt to parse an empty string. * In this case this should be None when thumbnail_url is an empty string */ //#[serde(with = "url_serde")] pub thumbnail_url: String, //Option, pub viewable: String, pub view_count: i32, pub language: String, #[serde(rename = "type")] pub video_type: String, //Should be converted to a Duration pub duration: String, } #[derive(Debug, Deserialize)] pub struct User { pub id: UserId, pub login: String, pub display_name: String, #[serde(rename = "type")] pub user_type: String, pub broadcaster_type: String, pub description: String, #[serde(with = "url_serde")] pub profile_image_url: Url, //#[serde(with = "url_serde")] pub offline_image_url: String, // Option, pub view_count: u32, pub email: Option, } #[derive(Debug, Deserialize)] pub struct Clip { pub id: String, #[serde(with = "url_serde")] pub url: Url, #[serde(with = "url_serde")] pub embed_url: Url, pub broadcaster_id: ChannelId, pub broadcaster_name: String, pub creator_id: UserId, pub creator_name: String, pub video_id: VideoId, pub game_id: String, pub language: String, pub title: String, pub created_at: DateTime, #[serde(with = "url_serde")] pub thumbnail_url: Url, pub view_count: i32, } #[derive(Debug, Deserialize)] pub struct Credentials { pub access_token: String, pub refresh_token: Option, pub expires_in: u32, pub scope: Option>, pub token_type: String, }