use super::*;
use helix::RequestPatch;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct UpdateChannelStreamScheduleSegmentRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
#[builder(setter(into))]
pub id: types::StreamSegmentId,
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct UpdateChannelStreamScheduleSegmentBody {
#[builder(default, setter(into))]
pub start_time: Option<String>,
#[builder(default, setter(into))]
pub duration: Option<String>,
#[builder(default, setter(into))]
pub category_id: Option<String>,
#[builder(default, setter(into))]
pub title: Option<String>,
#[builder(default, setter(into))]
pub is_canceled: Option<bool>,
#[builder(default, setter(into))]
pub timezone: Option<String>,
}
impl helix::private::SealedSerialize for UpdateChannelStreamScheduleSegmentBody {}
pub type UpdateChannelStreamScheduleSegmentResponse = ScheduledBroadcasts;
impl Request for UpdateChannelStreamScheduleSegmentRequest {
type Response = UpdateChannelStreamScheduleSegmentResponse;
const PATH: &'static str = "schedule/segment";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::ChannelManageSchedule];
}
impl RequestPatch for UpdateChannelStreamScheduleSegmentRequest {
type Body = UpdateChannelStreamScheduleSegmentBody;
fn parse_inner_response(
request: Option<Self>,
uri: &http::Uri,
response: &str,
status: http::StatusCode,
) -> Result<helix::Response<Self, Self::Response>, helix::HelixRequestPatchError>
where
Self: Sized,
{
let response: helix::InnerResponse<<Self as Request>::Response> =
helix::parse_json(response, true).map_err(|e| {
helix::HelixRequestPatchError::DeserializeError(
response.to_string(),
e,
uri.clone(),
status,
)
})?;
Ok(helix::Response {
data: response.data,
pagination: response.pagination.cursor,
request,
total: response.total,
other: None,
})
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = UpdateChannelStreamScheduleSegmentRequest::builder()
.broadcaster_id("141981764")
.id("eyJzZWdtZW50SUQiOiJlNGFjYzcyNC0zNzFmLTQwMmMtODFjYS0yM2FkYTc5NzU5ZDQiLCJpc29ZZWFyIjoyMDIxLCJpc29XZWVrIjoyNn0=")
.build();
let body = UpdateChannelStreamScheduleSegmentBody::builder()
.duration("120".to_string())
.build();
dbg!(req.create_request(body, "token", "clientid").unwrap());
let data = br#"
{
"data": {
"segments": [
{
"id": "eyJzZWdtZW50SUQiOiJlNGFjYzcyNC0zNzFmLTQwMmMtODFjYS0yM2FkYTc5NzU5ZDQiLCJpc29ZZWFyIjoyMDIxLCJpc29XZWVrIjoyNn0=",
"start_time": "2021-07-01T18:00:00Z",
"end_time": "2021-07-01T20: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
}
}
"#.to_vec();
let http_response = http::Response::builder().status(200).body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/schedule/segment?broadcaster_id=141981764&id=eyJzZWdtZW50SUQiOiJlNGFjYzcyNC0zNzFmLTQwMmMtODFjYS0yM2FkYTc5NzU5ZDQiLCJpc29ZZWFyIjoyMDIxLCJpc29XZWVrIjoyNn0%3D"
);
dbg!(
UpdateChannelStreamScheduleSegmentRequest::parse_response(Some(req), &uri, http_response)
.unwrap()
);
}