1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use std::fmt::Debug; use serde::{Serialize, Deserialize}; use crate::responses::*; use crate::{TwitchApi, Result}; #[derive(Debug, Serialize, Deserialize)] pub struct HelixGame { pub id: String, pub name: String, pub box_art_url: String } impl super::traits::HelixModel for HelixGame {} pub async fn get_top(twitch_api: &TwitchApi, first: i32, after: Option<String>, before: Option<String>) -> Result<HelixPaginatedResponse<HelixGame>> { let mut data: Vec<(&str, String)> = vec![ ("first", first.to_string()) ]; if let Some(value) = after { data.push(("after", value)); } if let Some(value) = before { data.push(("before", value)); } Ok( serde_json::from_str( &twitch_api.get(String::from("https://api.twitch.tv/helix/games/top"), &data) .await? .text() .await?[..] )? ) } pub async fn get(twitch_api: &TwitchApi, game_ids: &Vec<String>) -> Result<HelixResponse<HelixGame>> { let mut data: Vec<(&str, String)> = vec![]; for game_id in game_ids { data.push(("id", String::from(game_id))); } Ok( serde_json::from_str( &twitch_api.get(String::from("https://api.twitch.tv/helix/games"), &data) .await? .text() .await?[..] )? ) }