use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, 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 has_delay: Option<bool>,
}
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(),
has_delay: None,
}
}
pub const fn has_delay(mut self, has_delay: bool) -> Self {
self.has_delay = Some(has_delay);
self
}
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct CreatedClip {
pub id: types::ClipId,
pub edit_url: String,
}
impl Request for CreateClipRequest<'_> {
type Response = Vec<CreatedClip>;
const PATH: &'static str = "clips";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::ClipsEdit];
}
impl RequestGet for CreateClipRequest<'_> {}
#[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());
}