use super::*;
use helix::RequestGet;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetTopGamesRequest {
#[builder(default, setter(into))]
pub after: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub before: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub first: Option<usize>,
}
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: &'static [twitch_oauth2::Scope] = &[];
}
impl RequestGet for GetTopGamesRequest {}
impl helix::Paginated for GetTopGamesRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.after = cursor }
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetTopGamesRequest::builder().build();
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"
},
{
"id": "493057",
"name": "PLAYERUNKNOWN'S BATTLEGROUNDS",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/PLAYERUNKNOWN%27S%20BATTLEGROUNDS-{width}x{height}.jpg"
}
],
"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());
}