use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug, Default)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetTopGamesRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub after: Option<Cow<'a, helix::CursorRef>>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub before: Option<Cow<'a, helix::CursorRef>>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
pub first: Option<usize>,
}
impl GetTopGamesRequest<'_> {
pub const fn first(mut self, first: usize) -> Self {
self.first = Some(first);
self
}
}
pub type Game = types::TwitchCategory;
impl Request for GetTopGamesRequest<'_> {
type Response = Vec<Game>;
const PATH: &'static str = "games/top";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetTopGamesRequest<'_> {}
impl helix::Paginated for GetTopGamesRequest<'_> {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) {
self.after = cursor.map(|c| c.into_cow())
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetTopGamesRequest::default();
let data = br#"
{
"data": [
{
"id": "493057",
"name": "PLAYERUNKNOWN'S BATTLEGROUNDS",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN%27S%20BATTLEGROUNDS-{width}x{height}.jpg",
"igdb_id": "27789"
},
{
"id": "493057",
"name": "PLAYERUNKNOWN'S BATTLEGROUNDS",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN%27S%20BATTLEGROUNDS-{width}x{height}.jpg",
"igdb_id": "27789"
}
],
"pagination":{"cursor":"eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MjB9fQ=="}
}
"#
.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/top?");
dbg!(GetTopGamesRequest::parse_response(Some(req), &uri, http_response).unwrap());
}