Added API endpoints classes for all CFCore web API endpoints.
A few have not been implemented.
This commit is contained in:
parent
2b9bd4dc26
commit
e4d4134ef2
28
CFCoreAPI/Endpoints/Categories/CategoriesAPI.cs
Normal file
28
CFCoreAPI/Endpoints/Categories/CategoriesAPI.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using CFCoreAPI.Endpoints.Categories.Responses;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace CFCoreAPI.Endpoints.Categories
|
||||||
|
{
|
||||||
|
public class CategoriesAPI : APIBase
|
||||||
|
{
|
||||||
|
public CategoriesAPI(HttpClient httpClient) : base(httpClient)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<CategoriesResponse> GetCategories(int gameId, int? classId)
|
||||||
|
{
|
||||||
|
string url = "/v1/categories";
|
||||||
|
url = QueryHelpers.AddQueryString(url, "gameId", gameId.ToString());
|
||||||
|
if (classId != null) url = QueryHelpers.AddQueryString(url, "classId", classId.ToString());
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||||
|
|
||||||
|
CategoriesResponse result;
|
||||||
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
||||||
|
{
|
||||||
|
result = (await JsonSerializer.DeserializeAsync<CategoriesResponse>(contentStream))!;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace CFCoreAPI.Endpoints.Categories.Responses
|
||||||
|
{
|
||||||
|
public class CategoriesResponse
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public CategoriesResponse(
|
||||||
|
List<DataModel> data
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IReadOnlyList<DataModel> Data { get; }
|
||||||
|
|
||||||
|
public class DataModel
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public DataModel(
|
||||||
|
int id,
|
||||||
|
int gameId,
|
||||||
|
string name,
|
||||||
|
string slug,
|
||||||
|
string url,
|
||||||
|
string iconUrl,
|
||||||
|
DateTime dateModified,
|
||||||
|
bool isClass,
|
||||||
|
int classId,
|
||||||
|
int parentCategoryId,
|
||||||
|
int displayIndex
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Id = id;
|
||||||
|
this.GameId = gameId;
|
||||||
|
this.Name = name;
|
||||||
|
this.Slug = slug;
|
||||||
|
this.Url = url;
|
||||||
|
this.IconUrl = iconUrl;
|
||||||
|
this.DateModified = dateModified;
|
||||||
|
this.IsClass = isClass;
|
||||||
|
this.ClassId = classId;
|
||||||
|
this.ParentCategoryId = parentCategoryId;
|
||||||
|
this.DisplayIndex = displayIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; }
|
||||||
|
public int GameId { get; }
|
||||||
|
public string Name { get; }
|
||||||
|
public string Slug { get; }
|
||||||
|
public string Url { get; }
|
||||||
|
public string IconUrl { get; }
|
||||||
|
public DateTime DateModified { get; }
|
||||||
|
public bool IsClass { get; }
|
||||||
|
public int ClassId { get; }
|
||||||
|
public int ParentCategoryId { get; }
|
||||||
|
public int DisplayIndex { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using CFCoreAPI.Endpoints.Files.Requests;
|
||||||
using CFCoreAPI.Endpoints.Files.Responses;
|
using CFCoreAPI.Endpoints.Files.Responses;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
@ -34,8 +35,8 @@ namespace CFCoreAPI.Endpoints.Files
|
|||||||
if (index != null) QueryHelpers.AddQueryString(url, "index", index.ToString());
|
if (index != null) QueryHelpers.AddQueryString(url, "index", index.ToString());
|
||||||
if (pageSize != null) QueryHelpers.AddQueryString(url, "pageSize", pageSize.ToString());
|
if (pageSize != null) QueryHelpers.AddQueryString(url, "pageSize", pageSize.ToString());
|
||||||
HttpResponseMessage response = await httpClient.GetAsync(url);
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||||
ModFilesResponse result;
|
|
||||||
|
|
||||||
|
ModFilesResponse result;
|
||||||
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
||||||
{
|
{
|
||||||
result = await JsonSerializer.DeserializeAsync<ModFilesResponse>(contentStream);
|
result = await JsonSerializer.DeserializeAsync<ModFilesResponse>(contentStream);
|
||||||
@ -43,5 +44,46 @@ namespace CFCoreAPI.Endpoints.Files
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<FileResponse> GetFilesAsync(ModFilesRequest request)
|
||||||
|
{
|
||||||
|
string url = "/v1/mods/files";
|
||||||
|
HttpContent content = new StringContent(JsonSerializer.Serialize(request));
|
||||||
|
HttpResponseMessage response = await httpClient.PostAsync(url, content);
|
||||||
|
|
||||||
|
FileResponse result;
|
||||||
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
||||||
|
{
|
||||||
|
result = await JsonSerializer.DeserializeAsync<FileResponse>(contentStream);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StringResponse> GetModFileChangelog(int modId, int field)
|
||||||
|
{
|
||||||
|
string url = "/v1/mods/{0}/files/{1}/changelog";
|
||||||
|
string.Format(url, modId, field);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||||
|
|
||||||
|
StringResponse result;
|
||||||
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
||||||
|
{
|
||||||
|
result = await JsonSerializer.DeserializeAsync<StringResponse>(contentStream);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StringResponse> GetModFileDownloadURL(int modId, int field)
|
||||||
|
{
|
||||||
|
string url = "/v1/mods/{0}/files/{1}/download-url";
|
||||||
|
string.Format(url, modId, field);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||||
|
|
||||||
|
StringResponse result;
|
||||||
|
using (Stream contentStream = await response.Content.ReadAsStreamAsync())
|
||||||
|
{
|
||||||
|
result = await JsonSerializer.DeserializeAsync<StringResponse>(contentStream);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
19
CFCoreAPI/Endpoints/Files/Requests/ModFilesRequest.cs
Normal file
19
CFCoreAPI/Endpoints/Files/Requests/ModFilesRequest.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace CFCoreAPI.Endpoints.Files.Requests
|
||||||
|
{
|
||||||
|
public class ModFilesRequest
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public ModFilesRequest(
|
||||||
|
List<int> modIds
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.ModIds = modIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IReadOnlyList<int> ModIds { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
172
CFCoreAPI/Endpoints/Files/Responses/FileResponse.cs
Normal file
172
CFCoreAPI/Endpoints/Files/Responses/FileResponse.cs
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace CFCoreAPI.Endpoints.Files.Responses
|
||||||
|
{
|
||||||
|
public struct FileResponse
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public FileResponse(
|
||||||
|
List<DataModel> data
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IReadOnlyList<DataModel> Data { get; }
|
||||||
|
|
||||||
|
public struct DataModel
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public DataModel(
|
||||||
|
int id,
|
||||||
|
int gameId,
|
||||||
|
int modId,
|
||||||
|
bool isAvailable,
|
||||||
|
string displayName,
|
||||||
|
string fileName,
|
||||||
|
int releaseType,
|
||||||
|
int fileStatus,
|
||||||
|
List<HashModel> hashes,
|
||||||
|
DateTime fileDate,
|
||||||
|
int fileLength,
|
||||||
|
int downloadCount,
|
||||||
|
string downloadUrl,
|
||||||
|
List<string> gameVersions,
|
||||||
|
List<SortableGameVersion> sortableGameVersions,
|
||||||
|
List<DependencyModel> dependencies,
|
||||||
|
bool exposeAsAlternative,
|
||||||
|
int parentProjectFileId,
|
||||||
|
int alternateFileId,
|
||||||
|
bool isServerPack,
|
||||||
|
int serverPackFileId,
|
||||||
|
int fileFingerprint,
|
||||||
|
List<ModuleModel> modules
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Id = id;
|
||||||
|
this.GameId = gameId;
|
||||||
|
this.ModId = modId;
|
||||||
|
this.IsAvailable = isAvailable;
|
||||||
|
this.DisplayName = displayName;
|
||||||
|
this.FileName = fileName;
|
||||||
|
this.ReleaseType = releaseType;
|
||||||
|
this.FileStatus = fileStatus;
|
||||||
|
this.Hashes = hashes;
|
||||||
|
this.FileDate = fileDate;
|
||||||
|
this.FileLength = fileLength;
|
||||||
|
this.DownloadCount = downloadCount;
|
||||||
|
this.DownloadUrl = downloadUrl;
|
||||||
|
this.GameVersions = gameVersions;
|
||||||
|
this.SortableGameVersions = sortableGameVersions;
|
||||||
|
this.Dependencies = dependencies;
|
||||||
|
this.ExposeAsAlternative = exposeAsAlternative;
|
||||||
|
this.ParentProjectFileId = parentProjectFileId;
|
||||||
|
this.AlternateFileId = alternateFileId;
|
||||||
|
this.IsServerPack = isServerPack;
|
||||||
|
this.ServerPackFileId = serverPackFileId;
|
||||||
|
this.FileFingerprint = fileFingerprint;
|
||||||
|
this.Modules = modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; }
|
||||||
|
public int GameId { get; }
|
||||||
|
public int ModId { get; }
|
||||||
|
public bool IsAvailable { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
public string FileName { get; }
|
||||||
|
public int ReleaseType { get; }
|
||||||
|
public int FileStatus { get; }
|
||||||
|
public IReadOnlyList<HashModel> Hashes { get; }
|
||||||
|
public DateTime FileDate { get; }
|
||||||
|
public int FileLength { get; }
|
||||||
|
public int DownloadCount { get; }
|
||||||
|
public string DownloadUrl { get; }
|
||||||
|
public IReadOnlyList<string> GameVersions { get; }
|
||||||
|
public IReadOnlyList<SortableGameVersion> SortableGameVersions { get; }
|
||||||
|
public IReadOnlyList<DependencyModel> Dependencies { get; }
|
||||||
|
public bool ExposeAsAlternative { get; }
|
||||||
|
public int ParentProjectFileId { get; }
|
||||||
|
public int AlternateFileId { get; }
|
||||||
|
public bool IsServerPack { get; }
|
||||||
|
public int ServerPackFileId { get; }
|
||||||
|
public int FileFingerprint { get; }
|
||||||
|
public IReadOnlyList<ModuleModel> Modules { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DependencyModel
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public DependencyModel(
|
||||||
|
int modId,
|
||||||
|
int relationType
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.ModId = modId;
|
||||||
|
this.RelationType = relationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ModId { get; }
|
||||||
|
public int RelationType { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct HashModel
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public HashModel(
|
||||||
|
string value,
|
||||||
|
int algo
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Value = value;
|
||||||
|
this.Algo = algo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Value { get; }
|
||||||
|
public int Algo { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct ModuleModel
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public ModuleModel(
|
||||||
|
string name,
|
||||||
|
int fingerprint
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.Fingerprint = fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
|
public int Fingerprint { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct SortableGameVersion
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public SortableGameVersion(
|
||||||
|
string gameVersionName,
|
||||||
|
string gameVersionPadded,
|
||||||
|
string gameVersion,
|
||||||
|
DateTime gameVersionReleaseDate,
|
||||||
|
int gameVersionTypeId
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.GameVersionName = gameVersionName;
|
||||||
|
this.GameVersionPadded = gameVersionPadded;
|
||||||
|
this.GameVersion = gameVersion;
|
||||||
|
this.GameVersionReleaseDate = gameVersionReleaseDate;
|
||||||
|
this.GameVersionTypeId = gameVersionTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GameVersionName { get; }
|
||||||
|
public string GameVersionPadded { get; }
|
||||||
|
public string GameVersion { get; }
|
||||||
|
public DateTime GameVersionReleaseDate { get; }
|
||||||
|
public int GameVersionTypeId { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
10
CFCoreAPI/Endpoints/Fingerprints/FingerprintsAPI.cs
Normal file
10
CFCoreAPI/Endpoints/Fingerprints/FingerprintsAPI.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace CFCoreAPI.Endpoints.Fingerprints
|
||||||
|
{
|
||||||
|
public class FingerprintsAPI : APIBase
|
||||||
|
{
|
||||||
|
public FingerprintsAPI(HttpClient httpClient) : base(httpClient)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
CFCoreAPI/Endpoints/Minecraft/MinecraftAPI.cs
Normal file
10
CFCoreAPI/Endpoints/Minecraft/MinecraftAPI.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace CFCoreAPI.Endpoints.Minecraft
|
||||||
|
{
|
||||||
|
public class MinecraftAPI : APIBase
|
||||||
|
{
|
||||||
|
public MinecraftAPI(HttpClient httpClient) : base(httpClient)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
CFCoreAPI/Endpoints/Mods/ModsAPI.cs
Normal file
10
CFCoreAPI/Endpoints/Mods/ModsAPI.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace CFCoreAPI.Endpoints.Mods
|
||||||
|
{
|
||||||
|
public class ModsAPI : APIBase
|
||||||
|
{
|
||||||
|
public ModsAPI(HttpClient httpClient) : base(httpClient)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
CFCoreAPI/Endpoints/Responses/StringResponse.cs
Normal file
17
CFCoreAPI/Endpoints/Responses/StringResponse.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace CFCoreAPI.Endpoints.Files.Responses
|
||||||
|
{
|
||||||
|
public struct StringResponse
|
||||||
|
{
|
||||||
|
[JsonConstructor]
|
||||||
|
public StringResponse(
|
||||||
|
string data
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Data { get; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user