use super::*;
use helix::RequestGet;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetChannelStreamScheduleRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
#[builder(default, setter(into))]
pub id: Option<types::StreamSegmentId>,
#[builder(default, setter(into))]
pub start_time: Option<types::Timestamp>,
#[builder(default, setter(into))]
pub utc_offset: Option<String>,
#[builder(default)]
pub after: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub first: Option<usize>,
}
pub type GetChannelStreamScheduleResponse = ScheduledBroadcasts;
impl Request for GetChannelStreamScheduleRequest {
type Response = ScheduledBroadcasts;
const PATH: &'static str = "schedule";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
impl RequestGet for GetChannelStreamScheduleRequest {}
impl helix::Paginated for GetChannelStreamScheduleRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.after = cursor; }
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetChannelStreamScheduleRequest::builder()
.broadcaster_id("141981764")
.build();
let data = br#"
{
"data": {
"segments": [
{
"id": "eyJzZWdtZW50SUQiOiJlNGFjYzcyNC0zNzFmLTQwMmMtODFjYS0yM2FkYTc5NzU5ZDQiLCJpc29ZZWFyIjoyMDIxLCJpc29XZWVrIjoyNn0=",
"start_time": "2021-07-01T18:00:00Z",
"end_time": "2021-07-01T19:00:00Z",
"title": "TwitchDev Monthly Update // July 1, 2021",
"canceled_until": null,
"category": {
"id": "509670",
"name": "Science & Technology"
},
"is_recurring": false
}
],
"broadcaster_id": "141981764",
"broadcaster_name": "TwitchDev",
"broadcaster_login": "twitchdev",
"vacation": null
},
"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/schedule?broadcaster_id=141981764"
);
dbg!(GetChannelStreamScheduleRequest::parse_response(Some(req), &uri, http_response).unwrap());
}