cfcoreapi/CFCoreAPI/Endpoints/Files/FilesAPI.cs

47 lines
2.0 KiB
C#
Raw Normal View History

using System.Text.Json;
using CFCoreAPI.Endpoints.Files.Responses;
using Microsoft.AspNetCore.WebUtilities;
namespace CFCoreAPI.Endpoints.Files
{
public class FilesAPI : APIBase
{
public FilesAPI(HttpClient httpClient) : base(httpClient)
{
}
public async Task<ModFileResponse> GetModFileAsync(int modId, int fileId)
{
string url = "/v1/mods/{0}/files/{1}";
string.Format(url, modId, fileId);
HttpResponseMessage response = await httpClient.GetAsync(url);
ModFileResponse result;
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
{
result = await JsonSerializer.DeserializeAsync<ModFileResponse>(contentStream);
}
return result;
}
public async Task<ModFilesResponse> GetModFilesAsync(int modId, string? gameVersion = null, ModLoaderType? modLoaderType = null, int? gameVersionTypeId = null, int? index = null, int? pageSize = null)
{
string url = "/v1/mods/{0}/files";
string.Format(url, modId);
if (gameVersion != null) QueryHelpers.AddQueryString(url, "gameVersion", gameVersion);
if (modLoaderType != null) QueryHelpers.AddQueryString(url, "modLoaderType", ((int)modLoaderType.Value).ToString());
if (gameVersionTypeId != null) QueryHelpers.AddQueryString(url, "gameVersionTypeId", gameVersionTypeId.ToString());
if (index != null) QueryHelpers.AddQueryString(url, "index", index.ToString());
if (pageSize != null) QueryHelpers.AddQueryString(url, "pageSize", pageSize.ToString());
HttpResponseMessage response = await httpClient.GetAsync(url);
ModFilesResponse result;
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
{
result = await JsonSerializer.DeserializeAsync<ModFilesResponse>(contentStream);
}
return result;
}
}
}