use super::*;
use helix::RequestPost;
impl StartCommercialRequest {
pub fn new() -> Self { StartCommercialRequest {} }
}
#[derive(PartialEq, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct StartCommercialRequest {}
impl Default for StartCommercialRequest {
fn default() -> Self { StartCommercialRequest::new() }
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct StartCommercialBody {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
pub length: types::CommercialLength,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct StartCommercial {
pub length: types::CommercialLength,
pub message: String,
pub retry_after: u64,
}
impl Request for StartCommercialRequest {
type Response = Vec<StartCommercial>;
const PATH: &'static str = "channels/commercial";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::ChannelEditCommercial];
}
impl RequestPost for StartCommercialRequest {
type Body = StartCommercialBody;
}
impl helix::private::SealedSerialize for StartCommercialBody {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = StartCommercialRequest {};
let body = StartCommercialBody::builder()
.broadcaster_id("1234")
.length(crate::types::CommercialLength::Length120)
.build();
dbg!(req.create_request(body, "token", "clientid").unwrap());
let data = br#"
{
"data": [{
"length" : 60,
"message" : "",
"retry_after" : 480
}]
}
"#
.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/channels/commercial?"
);
dbg!(StartCommercialRequest::parse_response(Some(req), &uri, http_response).unwrap());
}