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 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(contentStream); } return result; } public async Task 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(contentStream); } return result; } public async Task 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(contentStream))!; } return result; } public async Task 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(contentStream))!; } return result; } } }