#![allow(deprecated_in_future, deprecated)]
use super::*;
use helix::RequestGet;
#[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>,
#[deprecated(
since = "0.6.0",
note = "this does nothing, see https://discuss.dev.twitch.tv/t/get-hype-train-events-api-endpoint-id-query-parameter-deprecation/37613"
)]
#[builder(default, setter(into))]
pub id: Option<String>,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_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, Serialize, Debug, Clone)]
#[non_exhaustive]
pub enum HypeTrainEventType {
#[serde(rename = "hypetrain.progression")]
Progression,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_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: types::HypeTrainId,
}
impl Request for GetHypeTrainEventsRequest {
type Response = Vec<HypeTrainEvent>;
const PATH: &'static str = "hypetrain/events";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
impl RequestGet for GetHypeTrainEventsRequest {}
impl helix::Paginated for GetHypeTrainEventsRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.cursor = cursor }
}
#[cfg(test)]
#[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());
}