use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug, Default)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetContentClassificationLabelsRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub locale: Option<Cow<'a, str>>,
}
impl<'a> GetContentClassificationLabelsRequest<'a> {
pub fn locale(locale: impl Into<Cow<'a, str>>) -> Self {
Self {
locale: Some(locale.into()),
}
}
pub fn new() -> Self { Self::default() }
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ContentClassificationLabel {
pub id: types::ContentClassificationId,
pub description: String,
pub name: String,
}
impl Request for GetContentClassificationLabelsRequest<'_> {
type Response = Vec<ContentClassificationLabel>;
const PATH: &'static str = "content_classification_labels";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetContentClassificationLabelsRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetContentClassificationLabelsRequest::new();
let data = br#"
{
"data": [
{
"description": "Discussions or debates about politics or sensitive social issues such as elections, civic integrity, military conflict, and civil rights in a polarizing manner.",
"id": "DebatedSocialIssuesAndPolitics",
"name": "Politics and Sensitive Social Issues"
},
{
"description": "Excessive tobacco glorification or promotion, any marijuana consumption/use, legal drug and alcohol induced intoxication, discussions of illegal drugs.",
"id": "DrugsIntoxication",
"name": "Drugs, Intoxication, or Excessive Tobacco Use"
},
{
"description": "Participating in online or in-person gambling, poker or fantasy sports, that involve the exchange of real money.",
"id": "Gambling",
"name": "Gambling"
},
{
"description": "Games that are rated Mature or less suitable for a younger audience.",
"id": "MatureGame",
"name": "Mature-rated game"
},
{
"description": "Prolonged, and repeated use of obscenities, profanities, and vulgarities, especially as a regular part of speech.",
"id": "ProfanityVulgarity",
"name": "Significant Profanity or Vulgarity"
},
{
"description": "Content that focuses on sexualized physical attributes and activities, sexual topics, or experiences.",
"id": "SexualThemes",
"name": "Sexual Themes"
},
{
"description": "Simulations and/or depictions of realistic violence, gore, extreme injury, or death.",
"id": "ViolentGraphic",
"name": "Violent and Graphic Depictions"
}
]
}
"#
.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/content_classification_labels?"
);
let res = GetContentClassificationLabelsRequest::parse_response(Some(req), &uri, http_response)
.unwrap()
.data;
assert_eq!(res.len(), 7);
assert_eq!(res[0].description, "Discussions or debates about politics or sensitive social issues such as elections, civic integrity, military conflict, and civil rights in a polarizing manner.");
assert_eq!(res[0].name, "Politics and Sensitive Social Issues");
assert_eq!(
res[0].id,
types::ContentClassificationId::DebatedSocialIssuesAndPolitics
);
assert_eq!(res[1].id, types::ContentClassificationId::DrugsIntoxication);
assert_eq!(res[2].id, types::ContentClassificationId::Gambling);
assert_eq!(res[3].id, types::ContentClassificationId::MatureGame);
assert_eq!(
res[4].id,
types::ContentClassificationId::ProfanityVulgarity
);
assert_eq!(res[5].id, types::ContentClassificationId::SexualThemes);
assert_eq!(res[6].id, types::ContentClassificationId::ViolentGraphic);
}
#[cfg(test)]
#[test]
fn test_request_locale() {
use helix::*;
let req = GetContentClassificationLabelsRequest::locale("th-TH");
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/content_classification_labels?locale=th-TH"
);
}