73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
using System.Net.Http;
|
|
using CFCoreAPI.Endpoints;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
using CFCoreAPI.Endpoints.Games.Responses;
|
|
using System.Text.Json;
|
|
|
|
namespace CFCoreAPI.Endpoints.Games
|
|
{
|
|
public class GamesAPI : APIBase
|
|
{
|
|
public GamesAPI(HttpClient httpClient) : base(httpClient)
|
|
{
|
|
}
|
|
|
|
// TODO: Likely should move generic calls to extension method or private helper method.
|
|
public async Task<GamesResponse> GetGamesAsync(int? index = null, int? pageSize = null)
|
|
{
|
|
string url = "/v1/games";
|
|
if (index != null) url = QueryHelpers.AddQueryString(url, "index", index.ToString());
|
|
if (pageSize != null) url = QueryHelpers.AddQueryString(url, "pageSize", pageSize.ToString());
|
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
|
|
|
GamesResponse result;
|
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
|
{
|
|
result = await JsonSerializer.DeserializeAsync<GamesResponse>(contentStream);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<GameResponse> GetGameAsync(string gameId)
|
|
{
|
|
string url = "/v1/games/{0}";
|
|
string.Format(url, gameId);
|
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
|
|
|
GameResponse result;
|
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
|
{
|
|
result = await JsonSerializer.DeserializeAsync<GameResponse>(contentStream);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<VersionsResponse> GetVersionsAsync(string gameId)
|
|
{
|
|
string url = "/v1/games/{0}/versions";
|
|
string.Format(url, gameId);
|
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
|
|
|
VersionsResponse result;
|
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
|
{
|
|
result = (await JsonSerializer.DeserializeAsync<VersionsResponse>(contentStream))!;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<VersionTypesResponse> GetVersionTypesAsync(string gameId)
|
|
{
|
|
string url = "/v1/games/{0}/version-types";
|
|
string.Format(url, gameId);
|
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
|
|
|
VersionTypesResponse result;
|
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
|
{
|
|
result = (await JsonSerializer.DeserializeAsync<VersionTypesResponse>(contentStream))!;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
} |