|
| 1 | +//! Gets information about Twitch content classification labels. |
| 2 | +//! [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) |
| 3 | +//! |
| 4 | +//! # Accessing the endpoint |
| 5 | +//! |
| 6 | +//! ## Request: [GetContentClassificationLabelsRequest] |
| 7 | +//! |
| 8 | +//! To use this endpoint, construct a [`GetContentClassificationLabelsRequest`] with the [`GetContentClassificationLabelsRequest::new()`] or [`GetContentClassificationLabelsRequest::locale()`] methods. |
| 9 | +//! |
| 10 | +//! ```rust, no_run |
| 11 | +//! use twitch_api::helix::ccls::get_content_classification_labels; |
| 12 | +//! let request = |
| 13 | +//! get_content_classification_labels::GetContentClassificationLabelsRequest::new(); |
| 14 | +//! // Get content classification labels for a specific locale |
| 15 | +//! let request = get_content_classification_labels::GetContentClassificationLabelsRequest::locale("es-MX"); |
| 16 | +//! ``` |
| 17 | +//! |
| 18 | +//! ## Response: [ContentClassificationLabel] |
| 19 | +//! |
| 20 | +//! Send the request to receive the response with [`HelixClient::req_get()`](helix::HelixClient::req_get). |
| 21 | +//! |
| 22 | +//! ```rust, no_run |
| 23 | +//! use twitch_api::helix::{self, ccls::get_content_classification_labels}; |
| 24 | +//! # use twitch_api::client; |
| 25 | +//! # #[tokio::main] |
| 26 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { |
| 27 | +//! # let client: helix::HelixClient<'static, client::DummyHttpClient> = helix::HelixClient::default(); |
| 28 | +//! # let token = twitch_oauth2::AccessToken::new("validtoken".to_string()); |
| 29 | +//! # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?; |
| 30 | +//! let request = get_content_classification_labels::GetContentClassificationLabelsRequest::new(); |
| 31 | +//! let response: Vec<get_content_classification_labels::ContentClassificationLabel> = client.req_get(request, &token).await?.data; |
| 32 | +//! # Ok(()) |
| 33 | +//! # } |
| 34 | +//! ``` |
| 35 | +//! |
| 36 | +//! You can also get the [`http::Request`] with [`request.create_request(&token, &client_id)`](helix::RequestGet::create_request) |
| 37 | +//! and parse the [`http::Response`] with [`GetContentClassificationLabelsRequest::parse_response(None, &request.get_uri(), response)`](GetContentClassificationLabelsRequest::parse_response) |
| 38 | +use super::*; |
| 39 | +use helix::RequestGet; |
| 40 | + |
| 41 | +/// Query Parameters for [Get Content Classification Labels](super::get_content_classification_labels) |
| 42 | +/// |
| 43 | +/// [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) |
| 44 | +#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug, Default)] |
| 45 | +#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))] |
| 46 | +#[must_use] |
| 47 | +#[non_exhaustive] |
| 48 | +pub struct GetContentClassificationLabelsRequest<'a> { |
| 49 | + /// Locale for the Content Classification Labels. You may specify a maximum of 1 locale. Default: `"en-US"` |
| 50 | + /// |
| 51 | + /// Supported locales: `"bg-BG", "cs-CZ", "da-DK", "da-DK", "de-DE", "el-GR", "en-GB", "en-US", "es-ES", "es-MX", "fi-FI", "fr-FR", "hu-HU", "it-IT", "ja-JP", "ko-KR", "nl-NL", "no-NO", "pl-PL", "pt-BT", "pt-PT", "ro-RO", "ru-RU", "sk-SK", "sv-SE", "th-TH", "tr-TR", "vi-VN", "zh-CN", "zh-TW"` |
| 52 | + #[cfg_attr(feature = "typed-builder", builder(default, setter(into)))] |
| 53 | + #[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))] |
| 54 | + pub locale: Option<Cow<'a, str>>, |
| 55 | +} |
| 56 | + |
| 57 | +impl<'a> GetContentClassificationLabelsRequest<'a> { |
| 58 | + /// Request content classification labels for some locale |
| 59 | + pub fn locale(locale: impl Into<Cow<'a, str>>) -> Self { |
| 60 | + Self { |
| 61 | + locale: Some(locale.into()), |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /// Returns an new [`GetContentClassificationLabelsRequest`] |
| 66 | + pub fn new() -> Self { Self::default() } |
| 67 | +} |
| 68 | + |
| 69 | +/// Return Values for [Get Content Classification Labels](super::get_content_classification_labels) |
| 70 | +/// |
| 71 | +/// [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) |
| 72 | +#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] |
| 73 | +#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))] |
| 74 | +#[non_exhaustive] |
| 75 | +pub struct ContentClassificationLabel { |
| 76 | + /// Unique identifier for the CCL. |
| 77 | + pub id: types::ContentClassificationId, |
| 78 | + /// Localized description of the CCL. |
| 79 | + pub description: String, |
| 80 | + /// Localized name of the CCL. |
| 81 | + pub name: String, |
| 82 | +} |
| 83 | + |
| 84 | +impl Request for GetContentClassificationLabelsRequest<'_> { |
| 85 | + type Response = Vec<ContentClassificationLabel>; |
| 86 | + |
| 87 | + const PATH: &'static str = "content_classification_labels"; |
| 88 | + #[cfg(feature = "twitch_oauth2")] |
| 89 | + const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![]; |
| 90 | +} |
| 91 | + |
| 92 | +impl RequestGet for GetContentClassificationLabelsRequest<'_> {} |
| 93 | + |
| 94 | +#[cfg(test)] |
| 95 | +#[test] |
| 96 | +fn test_request() { |
| 97 | + use helix::*; |
| 98 | + let req = GetContentClassificationLabelsRequest::new(); |
| 99 | + |
| 100 | + // From api call |
| 101 | + let data = br#" |
| 102 | + { |
| 103 | + "data": [ |
| 104 | + { |
| 105 | + "description": "Discussions or debates about politics or sensitive social issues such as elections, civic integrity, military conflict, and civil rights in a polarizing manner.", |
| 106 | + "id": "DebatedSocialIssuesAndPolitics", |
| 107 | + "name": "Politics and Sensitive Social Issues" |
| 108 | + }, |
| 109 | + { |
| 110 | + "description": "Excessive tobacco glorification or promotion, any marijuana consumption/use, legal drug and alcohol induced intoxication, discussions of illegal drugs.", |
| 111 | + "id": "DrugsIntoxication", |
| 112 | + "name": "Drugs, Intoxication, or Excessive Tobacco Use" |
| 113 | + }, |
| 114 | + { |
| 115 | + "description": "Participating in online or in-person gambling, poker or fantasy sports, that involve the exchange of real money.", |
| 116 | + "id": "Gambling", |
| 117 | + "name": "Gambling" |
| 118 | + }, |
| 119 | + { |
| 120 | + "description": "Games that are rated Mature or less suitable for a younger audience.", |
| 121 | + "id": "MatureGame", |
| 122 | + "name": "Mature-rated game" |
| 123 | + }, |
| 124 | + { |
| 125 | + "description": "Prolonged, and repeated use of obscenities, profanities, and vulgarities, especially as a regular part of speech.", |
| 126 | + "id": "ProfanityVulgarity", |
| 127 | + "name": "Significant Profanity or Vulgarity" |
| 128 | + }, |
| 129 | + { |
| 130 | + "description": "Content that focuses on sexualized physical attributes and activities, sexual topics, or experiences.", |
| 131 | + "id": "SexualThemes", |
| 132 | + "name": "Sexual Themes" |
| 133 | + }, |
| 134 | + { |
| 135 | + "description": "Simulations and/or depictions of realistic violence, gore, extreme injury, or death.", |
| 136 | + "id": "ViolentGraphic", |
| 137 | + "name": "Violent and Graphic Depictions" |
| 138 | + } |
| 139 | + ] |
| 140 | + } |
| 141 | + "# |
| 142 | + .to_vec(); |
| 143 | + |
| 144 | + let http_response = http::Response::builder().body(data).unwrap(); |
| 145 | + |
| 146 | + let uri = req.get_uri().unwrap(); |
| 147 | + assert_eq!( |
| 148 | + uri.to_string(), |
| 149 | + "https://api.twitch.tv/helix/content_classification_labels?" |
| 150 | + ); |
| 151 | + |
| 152 | + let res = GetContentClassificationLabelsRequest::parse_response(Some(req), &uri, http_response) |
| 153 | + .unwrap() |
| 154 | + .data; |
| 155 | + |
| 156 | + assert_eq!(res.len(), 7); |
| 157 | + |
| 158 | + 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."); |
| 159 | + assert_eq!(res[0].name, "Politics and Sensitive Social Issues"); |
| 160 | + |
| 161 | + assert_eq!( |
| 162 | + res[0].id, |
| 163 | + types::ContentClassificationId::DebatedSocialIssuesAndPolitics |
| 164 | + ); |
| 165 | + assert_eq!(res[1].id, types::ContentClassificationId::DrugsIntoxication); |
| 166 | + assert_eq!(res[2].id, types::ContentClassificationId::Gambling); |
| 167 | + assert_eq!(res[3].id, types::ContentClassificationId::MatureGame); |
| 168 | + assert_eq!( |
| 169 | + res[4].id, |
| 170 | + types::ContentClassificationId::ProfanityVulgarity |
| 171 | + ); |
| 172 | + assert_eq!(res[5].id, types::ContentClassificationId::SexualThemes); |
| 173 | + assert_eq!(res[6].id, types::ContentClassificationId::ViolentGraphic); |
| 174 | +} |
| 175 | + |
| 176 | +#[cfg(test)] |
| 177 | +#[test] |
| 178 | +fn test_request_locale() { |
| 179 | + use helix::*; |
| 180 | + let req = GetContentClassificationLabelsRequest::locale("th-TH"); |
| 181 | + |
| 182 | + let uri = req.get_uri().unwrap(); |
| 183 | + assert_eq!( |
| 184 | + uri.to_string(), |
| 185 | + "https://api.twitch.tv/helix/content_classification_labels?locale=th-TH" |
| 186 | + ); |
| 187 | +} |
0 commit comments