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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
use std::fmt::Debug; use serde::{Serialize, Deserialize}; use crate::responses::*; use crate::{TwitchApi, Result}; #[derive(Debug, Serialize, Deserialize)] pub struct HelixStream { pub id: String, pub user_id: String, pub user_name: String, pub game_id: String, pub r#type: String, pub title: String, pub viewer_count: i32, pub started_at: String, pub language: String, pub thumbnail_url: String } impl super::traits::HelixModel for HelixStream {} pub async fn get_from_games(twitch_api: &TwitchApi, game_ids: &Vec<String>, first: i32, after: Option<String>, before: Option<String>) -> Result<HelixPaginatedResponse<HelixStream>> { let mut data: Vec<(&str, String)> = vec![ ("first", first.to_string()) ]; for game_id in game_ids { data.push(("game_id", String::from(game_id))); } 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/streams"), &data) .await? .text() .await?[..] )? ) } pub async fn get_from_users(twitch_api: &TwitchApi, user_ids: &Vec<String>, first: i32, after: Option<String>, before: Option<String>) -> Result<HelixPaginatedResponse<HelixStream>> { let mut data: Vec<(&str, String)> = vec![ ("first", first.to_string()) ]; for user_id in user_ids { data.push(("user_id", String::from(user_id))); } 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/streams"), &data) .await? .text() .await?[..] )? ) }