mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-21 06:48:11 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using System.Linq;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sandbox.Twitch
|
|
{
|
|
internal partial class TwitchAPI
|
|
{
|
|
public class StreamResponse
|
|
{
|
|
[JsonPropertyName( "id" )]
|
|
public string Id { get; set; }
|
|
|
|
[JsonPropertyName( "user_id" )]
|
|
public string UserId { get; set; }
|
|
|
|
[JsonPropertyName( "user_login" )]
|
|
public string UserLogin { get; set; }
|
|
|
|
[JsonPropertyName( "user_name" )]
|
|
public string UserName { get; set; }
|
|
|
|
[JsonPropertyName( "game_id" )]
|
|
public string GameId { get; set; }
|
|
|
|
[JsonPropertyName( "game_name" )]
|
|
public string GameName { get; set; }
|
|
|
|
[JsonPropertyName( "type" )]
|
|
public string Type { get; set; }
|
|
|
|
[JsonPropertyName( "title" )]
|
|
public string Title { get; set; }
|
|
|
|
[JsonPropertyName( "viewer_count" )]
|
|
public int ViewerCount { get; set; }
|
|
|
|
[JsonPropertyName( "started_at" )]
|
|
public string StartedAt { get; set; }
|
|
|
|
[JsonPropertyName( "language" )]
|
|
public string Language { get; set; }
|
|
|
|
[JsonPropertyName( "thumbnail_url" )]
|
|
public string ThumbnailUrl { get; set; }
|
|
|
|
[JsonPropertyName( "tag_ids" )]
|
|
public string[] TagIds { get; set; }
|
|
|
|
[JsonPropertyName( "is_mature" )]
|
|
public bool IsMature { get; set; }
|
|
}
|
|
|
|
public class StreamsResponse
|
|
{
|
|
[JsonPropertyName( "data" )]
|
|
public StreamResponse[] Streams { get; set; }
|
|
|
|
public StreamResponse FirstOrDefault() => Streams != null && Streams.Length > 0 ? Streams.FirstOrDefault() : null;
|
|
}
|
|
|
|
public async Task<StreamResponse> GetStream( string userId )
|
|
{
|
|
var response = await Get<StreamsResponse>( $"/streams?user_id={userId}" );
|
|
return response.FirstOrDefault();
|
|
}
|
|
|
|
public Task<StreamsResponse> GetStreams( string gameId )
|
|
{
|
|
return Get<StreamsResponse>( $"/streams?game_id={gameId}" );
|
|
}
|
|
}
|
|
}
|
|
|