use super::*;
use helix::RequestPost;
#[derive(PartialEq, Deserialize, Serialize, Clone, Debug)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct CreateClipRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub broadcaster_id: Cow<'a, types::UserIdRef>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
pub duration: Option<f32>,
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub title: Option<Cow<'a, str>>,
}
impl<'a> CreateClipRequest<'a> {
pub fn broadcaster_id(broadcaster_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
Self {
broadcaster_id: broadcaster_id.into_cow(),
duration: None,
title: None,
}
}
pub fn duration(mut self, duration: f32) -> Self {
self.duration = Some(duration);
self
}
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
self.title = Some(title.into());
self
}
}
pub type CreatedClip = super::CreatedClip;
impl Request for CreateClipRequest<'_> {
type PaginationData = ();
type Response = CreatedClip;
const PATH: &'static str = "clips";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::ClipsEdit];
}
impl RequestPost for CreateClipRequest<'_> {
type Body = helix::EmptyBody;
fn parse_inner_response(
request: Option<Self>,
uri: &http::Uri,
response: &str,
status: http::StatusCode,
) -> Result<helix::Response<Self, <Self as Request>::Response>, helix::HelixRequestPostError>
where
Self: Sized,
{
helix::parse_single_return(request, uri, response, status)
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = CreateClipRequest::broadcaster_id("44322889");
let data = br#"
{
"data":
[{
"id": "FiveWordsForClipSlug",
"edit_url": "http://clips.twitch.tv/FiveWordsForClipSlug/edit"
}]
}
"#
.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/clips?broadcaster_id=44322889"
);
dbg!(CreateClipRequest::parse_response(Some(req), &uri, http_response).unwrap());
}