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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use super::*;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetHypeTrainEventsRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
#[builder(default)]
pub cursor: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub first: Option<usize>,
#[builder(default, setter(into))]
pub id: Option<String>,
}
#[derive(PartialEq, Deserialize, Debug, Clone)]
#[cfg_attr(not(feature = "allow_unknown_fields"), serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct HypeTrainEvent {
pub id: String,
pub event_type: HypeTrainEventType,
pub event_timestamp: types::Timestamp,
pub version: String,
pub event_data: HypeTrainEventData,
}
#[derive(PartialEq, Deserialize, Debug, Clone)]
#[non_exhaustive]
pub enum HypeTrainEventType {
#[serde(rename = "hypetrain.progression")]
Progression,
}
#[derive(PartialEq, Deserialize, Debug, Clone)]
#[cfg_attr(not(feature = "allow_unknown_fields"), serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct HypeTrainEventData {
pub broadcaster_id: types::UserId,
pub expires_at: types::Timestamp,
pub cooldown_end_time: types::Timestamp,
pub goal: i64,
pub last_contribution: Contribution,
pub level: i64,
pub started_at: types::Timestamp,
pub top_contributions: Vec<Contribution>,
pub total: i64,
pub id: String,
}
impl helix::Request for GetHypeTrainEventsRequest {
type Response = Vec<HypeTrainEvent>;
const PATH: &'static str = "hypetrain/events";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
impl helix::RequestGet for GetHypeTrainEventsRequest {}
impl helix::Paginated for GetHypeTrainEventsRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.cursor = cursor }
}
#[test]
fn test_request() {
use helix::*;
let req = GetHypeTrainEventsRequest::builder()
.broadcaster_id("270954519".to_string())
.build();
let data = br#"
{
"data": [
{
"id": "1b0AsbInCHZW2SQFQkCzqN07Ib2",
"event_type": "hypetrain.progression",
"event_timestamp": "2020-04-24T20:07:24Z",
"version": "1.0",
"event_data": {
"broadcaster_id": "270954519",
"cooldown_end_time": "2020-04-24T20:13:21.003802269Z",
"expires_at": "2020-04-24T20:12:21.003802269Z",
"goal": 1800,
"id": "70f0c7d8-ff60-4c50-b138-f3a352833b50",
"last_contribution": {
"total": 200,
"type": "BITS",
"user": "134247454"
},
"level": 2,
"started_at": "2020-04-24T20:05:47.30473127Z",
"top_contributions": [
{
"total": 600,
"type": "BITS",
"user": "134247450"
}
],
"total": 600
}
}
],
"pagination": {
"cursor": "eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6IjI3MDk1NDUxOToxNTg3NzU4ODQ0OjFiMEFzYkluQ0haVzJTUUZRa0N6cU4wN0liMiJ9fQ"
}
}
"#
.to_vec();
let http_response = http::Response::builder().body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/hypetrain/events?broadcaster_id=270954519"
);
dbg!(GetHypeTrainEventsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}