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 GetGamesRequest<'a> {
#[cfg_attr(
feature = "typed-builder",
builder(default_code = "types::Collection::default()", setter(into))
)]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
#[cfg_attr(not(feature = "deser_borrow"), serde(bound(deserialize = "'de: 'a")))]
pub id: types::Collection<'a, types::CategoryId>,
#[cfg_attr(
feature = "typed-builder",
builder(default_code = "types::Collection::default()", setter(into))
)]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub name: types::Collection<'a, String>,
}
impl<'a> GetGamesRequest<'a> {
pub fn names(names: impl Into<types::Collection<'a, String>>) -> Self {
Self {
name: names.into(),
..Self::empty()
}
}
pub fn ids(ids: impl Into<types::Collection<'a, types::CategoryId>>) -> Self {
Self {
id: ids.into(),
..Self::empty()
}
}
pub fn empty() -> Self {
Self {
id: types::Collection::default(),
name: types::Collection::default(),
}
}
}
pub type Game = types::TwitchCategory;
impl Request for GetGamesRequest<'_> {
type Response = Vec<Game>;
const PATH: &'static str = "games";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetGamesRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetGamesRequest::ids(vec!["493057"]);
let data = br#"
{
"data": [
{
"id": "33214",
"name": "Fortnite",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/33214-{width}x{height}.jpg",
"igdb_id": "1905"
},
{
"id": "33214",
"name": "Fortnite",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/33214-{width}x{height}.jpg",
"igdb_id": "1905"
}
],
"pagination": {
"cursor": "eyJiIjpudWxsLCJhIjp7IkN"
}
}
"#
.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/games?id=493057"
);
dbg!(GetGamesRequest::parse_response(Some(req), &uri, http_response).unwrap());
}