-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Get Content Classification Labels
#449
Open
Nerixyz
wants to merge
1
commit into
main
Choose a base branch
from
feat/ccls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
src/helix/endpoints/ccls/get_content_classification_labels.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
//! Gets information about Twitch content classification labels. | ||
//! [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) | ||
//! | ||
//! # Accessing the endpoint | ||
//! | ||
//! ## Request: [GetContentClassificationLabelsRequest] | ||
//! | ||
//! To use this endpoint, construct a [`GetContentClassificationLabelsRequest`] with the [`GetContentClassificationLabelsRequest::new()`] or [`GetContentClassificationLabelsRequest::locale()`] methods. | ||
//! | ||
//! ```rust, no_run | ||
//! use twitch_api::helix::ccls::get_content_classification_labels; | ||
//! let request = | ||
//! get_content_classification_labels::GetContentClassificationLabelsRequest::new(); | ||
//! // Get content classification labels for a specific locale | ||
//! let request = get_content_classification_labels::GetContentClassificationLabelsRequest::locale("es-MX"); | ||
//! ``` | ||
//! | ||
//! ## Response: [ContentClassificationLabel] | ||
//! | ||
//! Send the request to receive the response with [`HelixClient::req_get()`](helix::HelixClient::req_get). | ||
//! | ||
//! ```rust, no_run | ||
//! use twitch_api::helix::{self, ccls::get_content_classification_labels}; | ||
//! # use twitch_api::client; | ||
//! # #[tokio::main] | ||
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
//! # let client: helix::HelixClient<'static, client::DummyHttpClient> = helix::HelixClient::default(); | ||
//! # let token = twitch_oauth2::AccessToken::new("validtoken".to_string()); | ||
//! # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?; | ||
//! let request = get_content_classification_labels::GetContentClassificationLabelsRequest::new(); | ||
//! let response: Vec<get_content_classification_labels::ContentClassificationLabel> = client.req_get(request, &token).await?.data; | ||
//! # Ok(()) | ||
//! # } | ||
//! ``` | ||
//! | ||
//! You can also get the [`http::Request`] with [`request.create_request(&token, &client_id)`](helix::RequestGet::create_request) | ||
//! and parse the [`http::Response`] with [`GetContentClassificationLabelsRequest::parse_response(None, &request.get_uri(), response)`](GetContentClassificationLabelsRequest::parse_response) | ||
use super::*; | ||
use helix::RequestGet; | ||
|
||
/// Query Parameters for [Get Content Classification Labels](super::get_content_classification_labels) | ||
/// | ||
/// [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) | ||
#[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> { | ||
/// Locale for the Content Classification Labels. You may specify a maximum of 1 locale. Default: `"en-US"` | ||
/// | ||
/// 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"` | ||
#[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> { | ||
/// Request content classification labels for some locale | ||
pub fn locale(locale: impl Into<Cow<'a, str>>) -> Self { | ||
Self { | ||
locale: Some(locale.into()), | ||
} | ||
} | ||
|
||
/// Returns an new [`GetContentClassificationLabelsRequest`] | ||
pub fn new() -> Self { Self::default() } | ||
} | ||
|
||
/// Return Values for [Get Content Classification Labels](super::get_content_classification_labels) | ||
/// | ||
/// [`get-content-classification-labels`](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) | ||
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)] | ||
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))] | ||
#[non_exhaustive] | ||
pub struct ContentClassificationLabel { | ||
/// Unique identifier for the CCL. | ||
pub id: types::ContentClassificationId, | ||
/// Localized description of the CCL. | ||
pub description: String, | ||
/// Localized name of the CCL. | ||
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(); | ||
|
||
// From api call | ||
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::Other("DebatedSocialIssuesAndPolitics".to_string()) | ||
); | ||
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" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Helix endpoints regarding content classification cabels | ||
//! | ||
//! # Examples | ||
//! | ||
//! ```rust,no_run | ||
//! # use twitch_api::helix::{HelixClient, ccls::GetContentClassificationLabelsRequest}; | ||
//! # #[tokio::main] | ||
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
//! let client = HelixClient::default(); | ||
//! # let _: &HelixClient<twitch_api::DummyHttpClient> = &client; | ||
//! # let token = twitch_oauth2::AccessToken::new("validtoken".to_string()); | ||
//! # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?; | ||
//! let req = GetContentClassificationLabelsRequest::new(); | ||
//! | ||
//! println!("{:?}", &client.req_get(req, &token).await?.data); | ||
//! # Ok(()) | ||
//! # } | ||
//! ``` | ||
//! | ||
//! # Implemented endpoints | ||
//! | ||
//! <!-- generate with "cargo xtask overview" (with a nightly toolchain) --> | ||
//! <!-- BEGIN-OVERVIEW --> | ||
//! <details open><summary style="cursor: pointer">CCLs 🟢 1/1</summary> | ||
//! | ||
//! | Endpoint | Helper | Module | | ||
//! |---|---|---| | ||
//! | [Get Content Classification Labels](https://dev.twitch.tv/docs/api/reference#get-content-classification-labels) | [`HelixClient::get_content_classification_labels`](crate::helix::HelixClient::get_content_classification_labels), [`HelixClient::get_content_classification_labels_for_locale`](crate::helix::HelixClient::get_content_classification_labels_for_locale) | [`get_content_classification_labels`] | | ||
//! | ||
//! </details> | ||
//! | ||
//! <!-- END-OVERVIEW --> | ||
|
||
use crate::{ | ||
helix::{self, Request}, | ||
types, | ||
}; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use std::borrow::Cow; | ||
|
||
pub mod get_content_classification_labels; | ||
|
||
#[doc(inline)] | ||
pub use get_content_classification_labels::{ | ||
ContentClassificationLabel, GetContentClassificationLabelsRequest, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod bits; | ||
pub mod ccls; | ||
pub mod channels; | ||
pub mod charity; | ||
pub mod chat; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not worth a twitch-types release imo