-
Notifications
You must be signed in to change notification settings - Fork 15
/
response.rs
100 lines (89 loc) · 2.55 KB
/
response.rs
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
use chrono::{DateTime, Utc};
use serde::Deserialize;
use crate::db::types::{EventTrack, ExtraMetadata};
/// What the harvesting API returns.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct HarvestResponse {
#[serde(with = "chrono::serde::ts_milliseconds")]
pub(crate) includes_items_until: DateTime<Utc>,
pub(crate) has_more: bool,
pub(crate) items: Vec<HarvestItem>,
}
#[derive(Debug, Deserialize)]
#[serde(tag = "kind")]
#[serde(rename_all = "kebab-case")]
pub(crate) enum HarvestItem {
#[serde(rename_all = "camelCase")]
Event {
id: String,
title: String,
description: Option<String>,
part_of: Option<String>,
#[serde(with = "chrono::serde::ts_milliseconds")]
created: DateTime<Utc>,
creators: Vec<String>,
duration: i32,
tracks: Vec<Track>,
thumbnail: Option<String>,
acl: Acl,
is_live: bool,
metadata: ExtraMetadata,
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},
#[serde(rename_all = "camelCase")]
EventDeleted {
id: String,
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},
#[serde(rename_all = "camelCase")]
Series {
id: String,
title: String,
description: Option<String>,
acl: Acl,
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},
#[serde(rename_all = "camelCase")]
SeriesDeleted {
id: String,
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},
}
impl HarvestItem {
pub(crate) fn updated(&self) -> DateTime<Utc> {
match *self {
Self::Event { updated, .. } => updated,
Self::EventDeleted { updated, .. } => updated,
Self::Series { updated, .. } => updated,
Self::SeriesDeleted { updated, .. } => updated,
}
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Track {
uri: String,
flavor: String,
mimetype: Option<String>,
resolution: Option<[i32; 2]>,
}
impl Into<EventTrack> for Track {
fn into(self) -> EventTrack {
EventTrack {
uri: self.uri,
flavor: self.flavor,
mimetype: self.mimetype,
resolution: self.resolution.map(Into::into),
}
}
}
#[derive(Debug, Deserialize)]
pub(crate) struct Acl {
pub(crate) read: Vec<String>,
pub(crate) write: Vec<String>,
}