use super::*;
use helix::RequestPost;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct ManageHeldAutoModMessagesRequest {}
impl ManageHeldAutoModMessagesRequest {
pub fn new() -> Self { Self {} }
}
impl Default for ManageHeldAutoModMessagesRequest {
fn default() -> Self { Self::new() }
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct ManageHeldAutoModMessagesBody {
#[builder(setter(into))]
pub user_id: types::UserId,
#[builder(setter(into))]
pub msg_id: types::MsgId,
#[builder(setter(into))]
pub action: AutoModAction,
}
#[derive(PartialEq, Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "UPPERCASE")]
#[non_exhaustive]
pub enum AutoModAction {
Allow,
Deny,
}
impl From<bool> for AutoModAction {
fn from(b: bool) -> Self {
match b {
true => AutoModAction::Allow,
false => AutoModAction::Deny,
}
}
}
impl helix::private::SealedSerialize for ManageHeldAutoModMessagesBody {}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub enum ManageHeldAutoModMessages {
Success,
}
impl Request for ManageHeldAutoModMessagesRequest {
type Response = ManageHeldAutoModMessages;
const PATH: &'static str = "moderation/automod/message";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::ModerationRead];
}
impl RequestPost for ManageHeldAutoModMessagesRequest {
type Body = ManageHeldAutoModMessagesBody;
fn parse_inner_response<'d>(
request: Option<Self>,
uri: &http::Uri,
response: &str,
status: http::StatusCode,
) -> Result<helix::Response<Self, Self::Response>, helix::HelixRequestPostError>
where
Self: Sized,
{
match status {
http::StatusCode::NO_CONTENT => Ok(helix::Response {
data: ManageHeldAutoModMessages::Success,
pagination: None,
request,
total: None,
other: None,
}),
_ => Err(helix::HelixRequestPostError::InvalidResponse {
reason: "unexpected status",
response: response.to_string(),
status,
uri: uri.clone(),
}),
}
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = ManageHeldAutoModMessagesRequest::new();
let body = ManageHeldAutoModMessagesBody::builder()
.action(true)
.user_id("9327994")
.msg_id("836013710")
.build();
dbg!(req.create_request(body, "token", "clientid").unwrap());
let data = br#""#.to_vec();
let http_response = http::Response::builder().status(204).body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/moderation/automod/message?"
);
dbg!(ManageHeldAutoModMessagesRequest::parse_response(Some(req), &uri, http_response).unwrap());
}