use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetChannelInformationRequest<'a> {
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
#[cfg_attr(not(feature = "deser_borrow"), serde(bound(deserialize = "'de: 'a")))]
pub broadcaster_id: types::Collection<'a, types::UserId>,
}
impl<'a> GetChannelInformationRequest<'a> {
pub fn broadcaster_ids(
broadcaster_ids: impl Into<types::Collection<'a, types::UserId>>,
) -> Self {
Self {
broadcaster_id: broadcaster_ids.into(),
}
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelInformation {
pub broadcaster_id: types::UserId,
pub broadcaster_login: types::UserName,
pub broadcaster_name: types::DisplayName,
pub game_id: types::CategoryId,
pub game_name: types::CategoryId,
pub broadcaster_language: String,
pub title: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub delay: i64,
pub tags: Vec<String>,
pub content_classification_labels: Vec<types::ContentClassificationId>,
pub is_branded_content: bool,
}
impl Request for GetChannelInformationRequest<'_> {
type Response = Vec<ChannelInformation>;
const PATH: &'static str = "channels";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetChannelInformationRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let ids: &[&types::UserIdRef] = &["141981764".into()];
let req = GetChannelInformationRequest::broadcaster_ids(ids);
let data = br#"
{
"data": [
{
"broadcaster_id": "141981764",
"broadcaster_login": "twitchdev",
"broadcaster_name": "TwitchDev",
"broadcaster_language": "en",
"game_id": "509670",
"game_name": "Science & Technology",
"title": "TwitchDev Monthly Update // May 6, 2021",
"delay": 0,
"tags": ["DevsInTheKnow"],
"content_classification_labels": ["Gambling", "DrugsIntoxication", "MatureGame"],
"is_branded_content": false
}
]
}
"#
.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/channels?broadcaster_id=141981764"
);
dbg!(GetChannelInformationRequest::parse_response(Some(req), &uri, http_response).unwrap());
}