diff options
author | David Blajda <blajda@hotmail.com> | 2018-12-15 06:21:52 +0000 |
---|---|---|
committer | David Blajda <blajda@hotmail.com> | 2018-12-15 06:21:52 +0000 |
commit | a4c842eae14bef20d3d04ee4313251344edf431f (patch) | |
tree | 1685f11fd6bbe9f85cb51d479770b04692250c0c /src/helix/models.rs | |
parent | 8615cc2f030240ba2982dba893fe63f11a0c8a88 (diff) |
Deserialize Urls and Dates. Also implement custom Id types
Diffstat (limited to 'src/helix/models.rs')
-rw-r--r-- | src/helix/models.rs | 46 |
1 files changed, 26 insertions, 20 deletions
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<T> { @@ -22,17 +23,17 @@ pub struct PaginationContainer<T> { #[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<Utc>, + pub published_at: DateTime<Utc>, + #[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<String>, } @@ -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<Utc>, + #[serde(with = "url_serde")] + pub thumbnail_url: Url, pub view_count: i32, } |