summaryrefslogtreecommitdiff
path: root/src/helix/models.rs
blob: 4c1566c6bbc48d74efba298dc56cdf6f91370941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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<T> {
    pub data: Vec<T>
}

impl<T> PaginationTrait for DataContainer<T> {
    fn cursor<'a>(&'a self) -> Option<&'a str> { None }
}

impl<T> PaginationTrait for PaginationContainer<T> {
    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<T> {
    pub data: Vec<T>,
    pub pagination: Option<Cursor>
}

#[derive(Debug, Deserialize)]
pub struct Cursor {
    pub cursor: Option<String>
}

#[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<Utc>,
    pub published_at: DateTime<Utc>,
    #[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<Url>,
    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: Url,
    pub view_count: u32,
    pub email: Option<String>,
}

#[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<Utc>,
    #[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<String>,
    pub expires_in: u32,
    pub scope: Option<Vec<String>>,
    pub token_type: String,
}