use super::*;
use helix::RequestPost;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct AddBlockedTermRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
#[builder(setter(into))]
pub moderator_id: types::UserId,
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct AddBlockedTermBody {
pub text: String,
}
impl AddBlockedTermBody {
pub fn new(text: String) -> Self { Self { text } }
}
impl helix::private::SealedSerialize for AddBlockedTermBody {}
impl helix::HelixRequestBody for Vec<AddBlockedTermBody> {
fn try_to_body(&self) -> Result<hyper::body::Bytes, helix::BodyError> {
#[derive(Serialize)]
struct InnerBody<'a> {
data: &'a Vec<AddBlockedTermBody>,
}
serde_json::to_vec(&InnerBody { data: self })
.map_err(Into::into)
.map(Into::into)
}
}
pub type AddBlockedTermResponse = BlockedTerm;
impl Request for AddBlockedTermRequest {
type Response = Vec<BlockedTerm>;
const PATH: &'static str = "moderation/blocked_terms";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] =
&[twitch_oauth2::Scope::ModeratorManageBlockedTerms];
}
impl RequestPost for AddBlockedTermRequest {
type Body = AddBlockedTermBody;
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = AddBlockedTermRequest::builder()
.broadcaster_id("1234")
.moderator_id("5678")
.build();
let body = AddBlockedTermBody::new("A phrase I'm not fond of".to_string());
dbg!(req.create_request(body, "token", "clientid").unwrap());
let data = br#"
{
"data": [
{
"broadcaster_id": "713936733",
"moderator_id": "713936733",
"id": "3bb6e5d3-afb1-416c-ad4e-21af970ccfe7",
"text": "A phrase I'm not fond of",
"created_at": "2021-09-29T15:36:45Z",
"updated_at": "2021-09-29T15:36:45Z",
"expires_at": null
}
]
}
"#
.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/moderation/blocked_terms?broadcaster_id=1234&moderator_id=5678"
);
dbg!(AddBlockedTermRequest::parse_response(Some(req), &uri, http_response).unwrap());
}