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 GetTeamsRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub id: Option<Cow<'a, types::TeamIdRef>>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub name: Option<Cow<'a, str>>,
}
impl<'a> GetTeamsRequest<'a> {
pub fn id(id: impl types::IntoCow<'a, types::TeamIdRef> + 'a) -> Self {
Self {
id: Some(id.into_cow()),
name: None,
}
}
pub fn name(name: impl Into<Cow<'a, str>>) -> Self {
Self {
id: None,
name: Some(name.into()),
}
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Team {
pub users: Vec<types::User>,
#[serde(flatten)]
pub team: TeamInformation,
}
impl Request for GetTeamsRequest<'_> {
type Response = Vec<Team>;
#[cfg(feature = "twitch_oauth2")]
const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserReadEmail];
const PATH: &'static str = "teams";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetTeamsRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetTeamsRequest::id("6358");
let data = br#"
{
"data": [
{
"users": [
{
"user_id": "278217731",
"user_name": "mastermndio",
"user_login": "mastermndio"
},
{
"user_id": "41284990",
"user_name": "jenninexus",
"user_login": "jenninexus"
}
],
"background_image_url": null,
"banner": null,
"created_at": "2019-02-11T12:09:22Z",
"updated_at": "2020-11-18T15:56:41Z",
"info": "<p>An outgoing and enthusiastic group of friendly channels that write code, teach about technology, and promote the technical community.</p>",
"thumbnail_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/team-livecoders-team_logo_image-bf1d9a87ca81432687de60e24ad9593d-600x600.png",
"team_name": "livecoders",
"team_display_name": "Live Coders",
"id": "6358"
}
]
}
"#
.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/teams?id=6358");
dbg!(GetTeamsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}
#[cfg(test)]
#[test]
fn test_no_thumbnail() {
use helix::*;
let req = GetTeamsRequest::id("10920");
let data = br#"
{
"data": [
{
"background_image_url": null,
"banner": null,
"created_at": "2021-02-26T15:15:43Z",
"id": "10920",
"info": "info",
"team_display_name": "display",
"team_name": "partyanimals",
"thumbnail_url": null,
"updated_at": "2021-04-19T18:24:48Z",
"users": [
{
"user_id": "103198412",
"user_login": "findtherabbit",
"user_name": "FindTheRabbit"
},
{
"user_id": "126291224",
"user_login": "chri5py",
"user_name": "chri5py"
}
]
}
]
}
"#
.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/teams?id=10920"
);
dbg!(GetTeamsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}