use super::*;
use helix::RequestGet;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetVideosRequest {
#[builder(default)]
pub id: Vec<types::VideoId>,
#[builder(default, setter(into))]
pub user_id: Option<types::UserId>,
#[builder(default, setter(into))]
pub game_id: Option<types::CategoryId>,
#[builder(default)]
pub after: Option<helix::Cursor>,
#[builder(default)]
pub before: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub first: Option<usize>,
#[builder(default, setter(into))]
pub language: Option<String>,
#[builder(default, setter(into))]
pub period: Option<VideoPeriod>,
#[builder(default, setter(into))]
pub sort: Option<Sort>,
#[serde(rename = "type")]
#[builder(default, setter(into))]
pub type_: Option<VideoTypeFilter>,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Video {
pub created_at: types::Timestamp,
pub description: String,
pub duration: String,
pub id: types::VideoId,
pub language: String,
#[serde(deserialize_with = "helix::deserialize_default_from_null")]
pub muted_segments: Vec<MutedSegment>,
pub published_at: types::Timestamp,
pub stream_id: Option<types::StreamId>,
pub thumbnail_url: String,
pub title: String,
#[serde(rename = "type")]
pub type_: types::VideoType,
pub url: String,
pub user_id: types::UserId,
pub user_name: types::DisplayName,
pub user_login: types::UserName,
pub view_count: i64,
pub viewable: types::VideoPrivacy,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct MutedSegment {
pub duration: i64,
pub offset: i64,
}
impl Request for GetVideosRequest {
type Response = Vec<Video>;
const PATH: &'static str = "videos";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
impl RequestGet for GetVideosRequest {}
impl helix::Paginated for GetVideosRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.after = cursor }
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetVideosRequest::builder()
.id(vec!["234482848".into()])
.build();
let data = br#"
{
"data": [
{
"id": "335921245",
"stream_id": null,
"user_id": "141981764",
"user_login": "twitchdev",
"user_name": "TwitchDev",
"title": "Twitch Developers 101",
"description": "Welcome to Twitch development! Here is a quick overview of our products and information to help you get started.",
"created_at": "2018-11-14T21:30:18Z",
"published_at": "2018-11-14T22:04:30Z",
"url": "https://www.twitch.tv/videos/335921245",
"thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/d2nvs31859zcd8/twitchdev/335921245/ce0f3a7f-57a3-4152-bc06-0c6610189fb3/thumb/index-0000000000-%{width}x%{height}.jpg",
"viewable": "public",
"view_count": 1863062,
"language": "en",
"type": "upload",
"duration": "3m21s",
"muted_segments": [
{
"duration": 30,
"offset": 120
}
]
}
],
"pagination": {}
}
"#
.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/videos?id=234482848"
);
dbg!(GetVideosRequest::parse_response(Some(req), &uri, http_response).unwrap());
}