From a4c842eae14bef20d3d04ee4313251344edf431f Mon Sep 17 00:00:00 2001 From: David Blajda Date: Sat, 15 Dec 2018 06:21:52 +0000 Subject: Deserialize Urls and Dates. Also implement custom Id types --- src/helix/models.rs | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/helix/models.rs') diff --git a/src/helix/models.rs b/src/helix/models.rs index 2b01e7c..e4c58c3 100644 --- a/src/helix/models.rs +++ b/src/helix/models.rs @@ -1,8 +1,9 @@ extern crate serde_json; extern crate chrono; -use chrono::{Duration, DateTime, Utc}; - +use url::Url; +use chrono::{DateTime, Utc}; +use super::types::{UserId, VideoId, ChannelId}; #[derive(Debug, Deserialize)] pub struct DataContainer { @@ -22,17 +23,17 @@ pub struct PaginationContainer { #[derive(Debug, Deserialize)] pub struct Video { - pub id: String, - pub user_id: String, + pub id: VideoId, + pub user_id: UserId, pub user_name: String, pub title: String, pub description: String, - //Should be converted to a DateTime - pub created_at: String, - pub published_at: String, - //Should be converted to a URL - pub url: String, - pub thumbnail_url: String, + pub created_at: DateTime, + pub published_at: DateTime, + #[serde(with = "url_serde")] + pub url: Url, + #[serde(with = "url_serde")] + pub thumbnail_url: Url, pub viewable: String, pub view_count: i32, pub language: String, @@ -44,15 +45,17 @@ pub struct Video { #[derive(Debug, Deserialize)] pub struct User { - pub id: String, + pub id: UserId, pub login: String, pub display_name: String, #[serde(rename = "type")] pub user_type: String, pub broadcaster_type: String, pub description: String, - pub profile_image_url: String, - pub offline_image_url: String, + #[serde(with = "url_serde")] + pub profile_image_url: Url, + #[serde(with = "url_serde")] + pub offline_image_url: Url, pub view_count: u32, pub email: Option, } @@ -60,17 +63,20 @@ pub struct User { #[derive(Debug, Deserialize)] pub struct Clip { pub id: String, - pub url: String, - pub embed_url: String, - pub broadcaster_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: String, + pub creator_id: UserId, pub creator_name: String, - pub video_id: String, + pub video_id: VideoId, pub game_id: String, pub language: String, pub title: String, - pub created_at: String, - pub thumbnail_url: String, + pub created_at: DateTime, + #[serde(with = "url_serde")] + pub thumbnail_url: Url, pub view_count: i32, } -- cgit v1.2.3