From 9791de306c22c744732219dadfd97b7dd556a5b2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:35:18 -0400 Subject: minor cleanup, formatting, documentation (#336) --- src/StardewModdingAPI.sln | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/StardewModdingAPI.sln b/src/StardewModdingAPI.sln index a2e0ec44..3cf129c0 100644 --- a/src/StardewModdingAPI.sln +++ b/src/StardewModdingAPI.sln @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Installer EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Tests", "StardewModdingAPI.Tests\StardewModdingAPI.Tests.csproj", "{36CCB19E-92EB-48C7-9615-98EEFD45109B}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dewdrop", "..\Dewdrop\Dewdrop.csproj", "{A308F679-51A3-4006-92D5-BAEC7EBD01A1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,8 +81,23 @@ Global {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|Mixed Platforms.Build.0 = Release|x86 {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|x86.ActiveCfg = Release|x86 {36CCB19E-92EB-48C7-9615-98EEFD45109B}.Release|x86.Build.0 = Release|x86 + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|x86.ActiveCfg = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Debug|x86.Build.0 = Debug|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Any CPU.Build.0 = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|x86.ActiveCfg = Release|Any CPU + {A308F679-51A3-4006-92D5-BAEC7EBD01A1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {70143042-A862-47A8-A677-7C819DDC90DC} + EndGlobalSection EndGlobal -- cgit From cddcd9a8cfde182e843f8b2224d00ba742596c76 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:39:12 -0400 Subject: standardise project name (#336) --- .../Controllers/CheckController.cs | 66 ++++++++++++++++++++++ src/StardewModdingAPI.Web/Models/IModModel.cs | 12 ++++ .../Models/ModGenericModel.cs | 27 +++++++++ .../Models/NexusResponseModel.cs | 41 ++++++++++++++ src/StardewModdingAPI.Web/Program.cs | 27 +++++++++ .../Properties/launchSettings.json | 29 ++++++++++ .../StardewModdingAPI.Web.csproj | 27 +++++++++ src/StardewModdingAPI.Web/Startup.cs | 52 +++++++++++++++++ .../appsettings.Development.json | 10 ++++ src/StardewModdingAPI.Web/appsettings.json | 8 +++ src/StardewModdingAPI.sln | 2 +- 11 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 src/StardewModdingAPI.Web/Controllers/CheckController.cs create mode 100644 src/StardewModdingAPI.Web/Models/IModModel.cs create mode 100644 src/StardewModdingAPI.Web/Models/ModGenericModel.cs create mode 100644 src/StardewModdingAPI.Web/Models/NexusResponseModel.cs create mode 100644 src/StardewModdingAPI.Web/Program.cs create mode 100644 src/StardewModdingAPI.Web/Properties/launchSettings.json create mode 100644 src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj create mode 100644 src/StardewModdingAPI.Web/Startup.cs create mode 100644 src/StardewModdingAPI.Web/appsettings.Development.json create mode 100644 src/StardewModdingAPI.Web/appsettings.json (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs new file mode 100644 index 00000000..8ab4611b --- /dev/null +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Controllers +{ + /// Provides an API to perform mod update checks. + [Produces("application/json")] + [Route("api/check")] + public class CheckController : Controller + { + /********* + ** Public methods + *********/ + /// Fetch version metadata for the given mods. + /// The mods for which to fetch update metadata. + [HttpPost] + public async Task Post([FromBody] NexusResponseModel[] mods) + { + using (var client = new HttpClient()) + { + // the return array of mods + var modList = new List(); + + foreach (var mod in mods) + { + try + { + // create request with HttpRequestMessage + var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.ID}")); + + // add the Nexus Client useragent to get JSON response from the site + request.Headers.UserAgent.ParseAdd("Nexus Client v0.63.15"); + + // send the request out + var response = await client.SendAsync(request); + // ensure the response is valid (throws exception) + response.EnsureSuccessStatusCode(); + + // get the JSON string of the response + var stringResponse = await response.Content.ReadAsStringAsync(); + + // create the mod data from the JSON string + var modData = JsonConvert.DeserializeObject(stringResponse); + + // add to the list of mods + modList.Add(modData.ModInfo()); + } + catch (Exception ex) + { + var modData = mod.ModInfo(); + modData.Valid = false; + + modList.Add(modData); + } + } + + return JsonConvert.SerializeObject(modList, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + } + } + } +} diff --git a/src/StardewModdingAPI.Web/Models/IModModel.cs b/src/StardewModdingAPI.Web/Models/IModModel.cs new file mode 100644 index 00000000..2eadcaec --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/IModModel.cs @@ -0,0 +1,12 @@ +namespace StardewModdingAPI.Web.Models +{ + /// A mod metadata response which provides a method to extract generic info. + internal interface IModModel + { + /********* + ** Public methods + *********/ + /// Get basic mod metadata. + ModGenericModel ModInfo(); + } +} diff --git a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs new file mode 100644 index 00000000..208af416 --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs @@ -0,0 +1,27 @@ +namespace StardewModdingAPI.Web.Models +{ + /// Generic metadata about a mod. + public class ModGenericModel + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The mod's vendor ID. + public string Vendor { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + public string Url { get; set; } + + /// Whether the mod is valid. + public bool Valid { get; set; } = true; + } +} diff --git a/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs b/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs new file mode 100644 index 00000000..ae5c691c --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs @@ -0,0 +1,41 @@ +using Newtonsoft.Json; + +namespace StardewModdingAPI.Web.Models +{ + /// A mod metadata response from Nexus Mods. + public class NexusResponseModel : IModModel + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + [JsonProperty("mod_page_uri")] + public string Url { get; set; } + + + /********* + ** Public methods + *********/ + /// Get basic mod metadata. + public ModGenericModel ModInfo() + { + return new ModGenericModel + { + ID = this.ID, + Version = this.Version, + Name = this.Name, + Url = this.Url, + Vendor = "Nexus" + }; + } + } +} diff --git a/src/StardewModdingAPI.Web/Program.cs b/src/StardewModdingAPI.Web/Program.cs new file mode 100644 index 00000000..5e258acc --- /dev/null +++ b/src/StardewModdingAPI.Web/Program.cs @@ -0,0 +1,27 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; + +namespace StardewModdingAPI.Web +{ + /// The main app entry point. + public class Program + { + /********* + ** Public methods + *********/ + /// The main app entry point. + /// The command-line arguments. + public static void Main(string[] args) + { + // configure web server + new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .UseApplicationInsights() + .Build() + .Run(); + } + } +} diff --git a/src/StardewModdingAPI.Web/Properties/launchSettings.json b/src/StardewModdingAPI.Web/Properties/launchSettings.json new file mode 100644 index 00000000..c15134dc --- /dev/null +++ b/src/StardewModdingAPI.Web/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59482/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/check", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Dewdrop": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/check", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:59483" + } + } +} diff --git a/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj new file mode 100644 index 00000000..fa1d88eb --- /dev/null +++ b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp1.1 + portable-net45+win8 + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/StardewModdingAPI.Web/Startup.cs b/src/StardewModdingAPI.Web/Startup.cs new file mode 100644 index 00000000..c7a5e8fe --- /dev/null +++ b/src/StardewModdingAPI.Web/Startup.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace StardewModdingAPI.Web +{ + /// The web app startup configuration. + public class Startup + { + /********* + ** Accessors + *********/ + /// The web app configuration. + public IConfigurationRoot Configuration { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The hosting environment. + public Startup(IHostingEnvironment env) + { + this.Configuration = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables() + .Build(); + } + + /// The method called by the runtime to add services to the container. + /// The service injection container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + /// The method called by the runtime to configure the HTTP request pipeline. + /// The application builder. + /// The hosting environment. + /// The logger factory. + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(this.Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + app.UseMvc(); + } + } +} diff --git a/src/StardewModdingAPI.Web/appsettings.Development.json b/src/StardewModdingAPI.Web/appsettings.Development.json new file mode 100644 index 00000000..fa8ce71a --- /dev/null +++ b/src/StardewModdingAPI.Web/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/src/StardewModdingAPI.Web/appsettings.json b/src/StardewModdingAPI.Web/appsettings.json new file mode 100644 index 00000000..5fff67ba --- /dev/null +++ b/src/StardewModdingAPI.Web/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning" + } + } +} diff --git a/src/StardewModdingAPI.sln b/src/StardewModdingAPI.sln index 3cf129c0..031e2d5f 100644 --- a/src/StardewModdingAPI.sln +++ b/src/StardewModdingAPI.sln @@ -29,7 +29,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Installer EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardewModdingAPI.Tests", "StardewModdingAPI.Tests\StardewModdingAPI.Tests.csproj", "{36CCB19E-92EB-48C7-9615-98EEFD45109B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dewdrop", "..\Dewdrop\Dewdrop.csproj", "{A308F679-51A3-4006-92D5-BAEC7EBD01A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StardewModdingAPI.Web", "StardewModdingAPI.Web\StardewModdingAPI.Web.csproj", "{A308F679-51A3-4006-92D5-BAEC7EBD01A1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -- cgit From 1bd59fc1d82d6d6316812a5609f61c4157af78c3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:48:47 -0400 Subject: split input model from Nexus response model (#336) --- src/StardewModdingAPI.Web/Controllers/CheckController.cs | 16 ++++++++-------- src/StardewModdingAPI.Web/Models/ModSearchModel.cs | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 src/StardewModdingAPI.Web/Models/ModSearchModel.cs (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs index 8ab4611b..47b61b2f 100644 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -19,7 +19,7 @@ namespace StardewModdingAPI.Web.Controllers /// Fetch version metadata for the given mods. /// The mods for which to fetch update metadata. [HttpPost] - public async Task Post([FromBody] NexusResponseModel[] mods) + public async Task Post([FromBody] ModSearchModel[] mods) { using (var client = new HttpClient()) { @@ -28,10 +28,13 @@ namespace StardewModdingAPI.Web.Controllers foreach (var mod in mods) { + if (!mod.NexusID.HasValue) + continue; + try { // create request with HttpRequestMessage - var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.ID}")); + var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.NexusID}")); // add the Nexus Client useragent to get JSON response from the site request.Headers.UserAgent.ParseAdd("Nexus Client v0.63.15"); @@ -42,7 +45,7 @@ namespace StardewModdingAPI.Web.Controllers response.EnsureSuccessStatusCode(); // get the JSON string of the response - var stringResponse = await response.Content.ReadAsStringAsync(); + string stringResponse = await response.Content.ReadAsStringAsync(); // create the mod data from the JSON string var modData = JsonConvert.DeserializeObject(stringResponse); @@ -50,12 +53,9 @@ namespace StardewModdingAPI.Web.Controllers // add to the list of mods modList.Add(modData.ModInfo()); } - catch (Exception ex) + catch (Exception) { - var modData = mod.ModInfo(); - modData.Valid = false; - - modList.Add(modData); + modList.Add(new ModGenericModel { ID = mod.NexusID.Value, Vendor = "Nexus", Valid = false }); } } diff --git a/src/StardewModdingAPI.Web/Models/ModSearchModel.cs b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs new file mode 100644 index 00000000..eb9ac920 --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Web.Models +{ + /// The search criteria for a mod. + public class ModSearchModel + { + /// The Nexus Mods ID (if any). + public int? NexusID { get; set; } + } +} -- cgit From dfae52b1e57677c1efa052b1073a2e8a56f32163 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Sep 2017 23:50:34 -0400 Subject: fix manual serialisation (#336) --- src/StardewModdingAPI.Web/Controllers/CheckController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs index 47b61b2f..a7582edd 100644 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -19,7 +19,7 @@ namespace StardewModdingAPI.Web.Controllers /// Fetch version metadata for the given mods. /// The mods for which to fetch update metadata. [HttpPost] - public async Task Post([FromBody] ModSearchModel[] mods) + public async Task Post([FromBody] ModSearchModel[] mods) { using (var client = new HttpClient()) { @@ -59,7 +59,7 @@ namespace StardewModdingAPI.Web.Controllers } } - return JsonConvert.SerializeObject(modList, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + return modList.ToArray(); } } } -- cgit From edbc3ef3c08909486d6c4b8797f0e3c2934854fa Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 22 Sep 2017 00:13:04 -0400 Subject: refactor Nexus code into generic vendor, rewrite using fluent HTTP client (#336) --- .../Controllers/CheckController.cs | 46 +++---------- .../Framework/IModRepository.cs | 17 +++++ .../Framework/NexusModsClient.cs | 75 ++++++++++++++++++++++ src/StardewModdingAPI.Web/Models/IModModel.cs | 12 ---- .../Models/ModGenericModel.cs | 43 +++++++++++-- .../Models/NexusResponseModel.cs | 41 ------------ .../StardewModdingAPI.Web.csproj | 1 + 7 files changed, 139 insertions(+), 96 deletions(-) create mode 100644 src/StardewModdingAPI.Web/Framework/IModRepository.cs create mode 100644 src/StardewModdingAPI.Web/Framework/NexusModsClient.cs delete mode 100644 src/StardewModdingAPI.Web/Models/IModModel.cs delete mode 100644 src/StardewModdingAPI.Web/Models/NexusResponseModel.cs (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs index a7582edd..9ec068cb 100644 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -1,9 +1,7 @@ -using System; using System.Collections.Generic; -using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; +using StardewModdingAPI.Web.Framework; using StardewModdingAPI.Web.Models; namespace StardewModdingAPI.Web.Controllers @@ -21,45 +19,19 @@ namespace StardewModdingAPI.Web.Controllers [HttpPost] public async Task Post([FromBody] ModSearchModel[] mods) { - using (var client = new HttpClient()) + using (NexusModsClient client = new NexusModsClient()) { - // the return array of mods - var modList = new List(); + List result = new List(); - foreach (var mod in mods) + foreach (ModSearchModel mod in mods) { - if (!mod.NexusID.HasValue) - continue; - - try - { - // create request with HttpRequestMessage - var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.NexusID}")); - - // add the Nexus Client useragent to get JSON response from the site - request.Headers.UserAgent.ParseAdd("Nexus Client v0.63.15"); - - // send the request out - var response = await client.SendAsync(request); - // ensure the response is valid (throws exception) - response.EnsureSuccessStatusCode(); - - // get the JSON string of the response - string stringResponse = await response.Content.ReadAsStringAsync(); - - // create the mod data from the JSON string - var modData = JsonConvert.DeserializeObject(stringResponse); - - // add to the list of mods - modList.Add(modData.ModInfo()); - } - catch (Exception) - { - modList.Add(new ModGenericModel { ID = mod.NexusID.Value, Vendor = "Nexus", Valid = false }); - } + if (mod.NexusID.HasValue) + result.Add(await client.GetModInfoAsync(mod.NexusID.Value)); + else + result.Add(new ModGenericModel(null, mod.NexusID ?? 0)); } - return modList.ToArray(); + return result.ToArray(); } } } diff --git a/src/StardewModdingAPI.Web/Framework/IModRepository.cs b/src/StardewModdingAPI.Web/Framework/IModRepository.cs new file mode 100644 index 00000000..ebf9850f --- /dev/null +++ b/src/StardewModdingAPI.Web/Framework/IModRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Framework +{ + /// A repository which provides mod metadata. + internal interface IModRepository : IDisposable + { + /********* + ** Public methods + *********/ + /// Get metadata about a mod in the repository. + /// The mod ID in this repository. + Task GetModInfoAsync(int id); + } +} diff --git a/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs b/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs new file mode 100644 index 00000000..8f010d56 --- /dev/null +++ b/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs @@ -0,0 +1,75 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Pathoschild.Http.Client; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Framework +{ + /// An HTTP client for fetching mod metadata from Nexus Mods. + internal class NexusModsClient : IModRepository + { + /********* + ** Properties + *********/ + /// The underlying HTTP client. + private readonly IClient Client; + + /********* + ** Public methods + *********/ + /// Construct an instance. + public NexusModsClient() + { + this.Client = new FluentClient("http://www.nexusmods.com/stardewvalley") + .SetUserAgent("Nexus Client v0.63.15"); + } + + /// Get metadata about a mod in the repository. + /// The mod ID in this repository. + public async Task GetModInfoAsync(int id) + { + try + { + NexusResponseModel response = await this.Client + .GetAsync($"mods/{id}") + .As(); + return new ModGenericModel("Nexus", id, response.Name, response.Version, response.Url); + } + catch (Exception) + { + return new ModGenericModel("Nexus", id); + } + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + this.Client.Dispose(); + } + + + /********* + ** Private models + *********/ + /// A mod metadata response from Nexus Mods. + private class NexusResponseModel + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public int ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + [JsonProperty("mod_page_uri")] + public string Url { get; set; } + } + } +} diff --git a/src/StardewModdingAPI.Web/Models/IModModel.cs b/src/StardewModdingAPI.Web/Models/IModModel.cs deleted file mode 100644 index 2eadcaec..00000000 --- a/src/StardewModdingAPI.Web/Models/IModModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace StardewModdingAPI.Web.Models -{ - /// A mod metadata response which provides a method to extract generic info. - internal interface IModModel - { - /********* - ** Public methods - *********/ - /// Get basic mod metadata. - ModGenericModel ModInfo(); - } -} diff --git a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs index 208af416..dc36c7f4 100644 --- a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs +++ b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs @@ -7,21 +7,52 @@ namespace StardewModdingAPI.Web.Models ** Accessors *********/ /// The unique mod ID. - public int ID { get; set; } + public int ID { get; } /// The mod name. - public string Name { get; set; } + public string Name { get; } /// The mod's vendor ID. - public string Vendor { get; set; } + public string Vendor { get; } /// The mod's semantic version number. - public string Version { get; set; } + public string Version { get; } /// The mod's web URL. - public string Url { get; set; } + public string Url { get; } /// Whether the mod is valid. - public bool Valid { get; set; } = true; + public bool Valid { get; } + + + /********* + ** Public methods + *********/ + /// Construct a valid instance. + /// The mod's vendor ID. + /// The unique mod ID. + /// The mod name. + /// The mod's semantic version number. + /// The mod's web URL. + /// Whether the mod is valid. + public ModGenericModel(string vendor, int id, string name, string version, string url, bool valid = true) + { + this.Vendor = vendor; + this.ID = id; + this.Name = name; + this.Version = version; + this.Url = url; + this.Valid = valid; + } + + /// Construct an valid instance. + /// The mod's vendor ID. + /// The unique mod ID. + public ModGenericModel(string vendor, int id) + { + this.Vendor = vendor; + this.ID = id; + this.Valid = false; + } } } diff --git a/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs b/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs deleted file mode 100644 index ae5c691c..00000000 --- a/src/StardewModdingAPI.Web/Models/NexusResponseModel.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Newtonsoft.Json; - -namespace StardewModdingAPI.Web.Models -{ - /// A mod metadata response from Nexus Mods. - public class NexusResponseModel : IModModel - { - /********* - ** Accessors - *********/ - /// The unique mod ID. - public int ID { get; set; } - - /// The mod name. - public string Name { get; set; } - - /// The mod's semantic version number. - public string Version { get; set; } - - /// The mod's web URL. - [JsonProperty("mod_page_uri")] - public string Url { get; set; } - - - /********* - ** Public methods - *********/ - /// Get basic mod metadata. - public ModGenericModel ModInfo() - { - return new ModGenericModel - { - ID = this.ID, - Version = this.Version, - Name = this.Name, - Url = this.Url, - Vendor = "Nexus" - }; - } - } -} diff --git a/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj index fa1d88eb..eee0f3f3 100644 --- a/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj +++ b/src/StardewModdingAPI.Web/StardewModdingAPI.Web.csproj @@ -19,6 +19,7 @@ + -- cgit From 2c02dfe45a6d1252bfef557db8f39f97e57d3d19 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 22 Sep 2017 00:47:46 -0400 Subject: rewrite to make update-check logic vendor-agnostic (#336) --- .../Controllers/CheckController.cs | 71 ++++++++++++++++--- .../Framework/IModRepository.cs | 17 ----- .../Framework/ModRepositories/IModRepository.cs | 24 +++++++ .../Framework/ModRepositories/NexusRepository.cs | 80 ++++++++++++++++++++++ .../Framework/NexusModsClient.cs | 75 -------------------- .../Models/ModGenericModel.cs | 37 +++++----- src/StardewModdingAPI.Web/Models/ModSearchModel.cs | 6 +- 7 files changed, 184 insertions(+), 126 deletions(-) delete mode 100644 src/StardewModdingAPI.Web/Framework/IModRepository.cs create mode 100644 src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs create mode 100644 src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs delete mode 100644 src/StardewModdingAPI.Web/Framework/NexusModsClient.cs (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs index 9ec068cb..2a346cf3 100644 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -1,7 +1,9 @@ +using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using StardewModdingAPI.Web.Framework; +using StardewModdingAPI.Web.Framework.ModRepositories; using StardewModdingAPI.Web.Models; namespace StardewModdingAPI.Web.Controllers @@ -11,28 +13,75 @@ namespace StardewModdingAPI.Web.Controllers [Route("api/check")] public class CheckController : Controller { + /********* + ** Properties + *********/ + /// The mod repositories which provide mod metadata. + private readonly IDictionary Repositories = + new IModRepository[] + { + new NexusRepository() + } + .ToDictionary(p => p.VendorKey, StringComparer.CurrentCultureIgnoreCase); + + /********* ** Public methods *********/ /// Fetch version metadata for the given mods. - /// The mods for which to fetch update metadata. + /// The mod update search criteria. [HttpPost] - public async Task Post([FromBody] ModSearchModel[] mods) + public async Task Post([FromBody] ModSearchModel search) { - using (NexusModsClient client = new NexusModsClient()) + IList result = new List(); + + foreach (string modKey in search.ModKeys) { - List result = new List(); + // parse mod key + if (!this.TryParseModKey(modKey, out string vendorKey, out string modID)) + { + result.Add(new ModGenericModel(modKey, "The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'.")); + continue; + } - foreach (ModSearchModel mod in mods) + // get matching repository + if (!this.Repositories.TryGetValue(vendorKey, out IModRepository repository)) { - if (mod.NexusID.HasValue) - result.Add(await client.GetModInfoAsync(mod.NexusID.Value)); - else - result.Add(new ModGenericModel(null, mod.NexusID ?? 0)); + result.Add(new ModGenericModel(modKey, "There's no mod repository matching this namespaced mod ID.")); + continue; } - return result.ToArray(); + // fetch mod info + result.Add(await repository.GetModInfoAsync(modID)); } + + return result.ToArray(); + } + + + /********* + ** Private methods + *********/ + /// Parse a namespaced mod ID. + /// The raw mod ID to parse. + /// The parsed vendor key. + /// The parsed mod ID. + /// Returns whether the value could be parsed. + private bool TryParseModKey(string raw, out string vendorKey, out string modID) + { + // split parts + string[] parts = raw?.Split(':'); + if (parts == null || parts.Length != 2) + { + vendorKey = null; + modID = null; + return false; + } + + // parse + vendorKey = parts[0]; + modID = parts[1]; + return true; } } } diff --git a/src/StardewModdingAPI.Web/Framework/IModRepository.cs b/src/StardewModdingAPI.Web/Framework/IModRepository.cs deleted file mode 100644 index ebf9850f..00000000 --- a/src/StardewModdingAPI.Web/Framework/IModRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Threading.Tasks; -using StardewModdingAPI.Web.Models; - -namespace StardewModdingAPI.Web.Framework -{ - /// A repository which provides mod metadata. - internal interface IModRepository : IDisposable - { - /********* - ** Public methods - *********/ - /// Get metadata about a mod in the repository. - /// The mod ID in this repository. - Task GetModInfoAsync(int id); - } -} diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs new file mode 100644 index 00000000..43bad4e9 --- /dev/null +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Framework.ModRepositories +{ + /// A repository which provides mod metadata. + internal interface IModRepository : IDisposable + { + /********* + ** Accessors + *********/ + /// The unique key for this vendor. + string VendorKey { get; } + + + /********* + ** Public methods + *********/ + /// Get metadata about a mod in the repository. + /// The mod ID in this repository. + Task GetModInfoAsync(string id); + } +} diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs new file mode 100644 index 00000000..37f309da --- /dev/null +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs @@ -0,0 +1,80 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Pathoschild.Http.Client; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Framework.ModRepositories +{ + /// An HTTP client for fetching mod metadata from Nexus Mods. + internal class NexusRepository : IModRepository + { + /********* + ** Properties + *********/ + /// The underlying HTTP client. + private readonly IClient Client; + + + /********* + ** Accessors + *********/ + /// The unique key for this vendor. + public string VendorKey { get; } = "Nexus"; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + public NexusRepository() + { + this.Client = new FluentClient("http://www.nexusmods.com/stardewvalley") + .SetUserAgent("Nexus Client v0.63.15"); + } + + /// Get metadata about a mod in the repository. + /// The mod ID in this repository. + public async Task GetModInfoAsync(string id) + { + try + { + NexusResponseModel response = await this.Client + .GetAsync($"mods/{id}") + .As(); + return new ModGenericModel($"{this.VendorKey}:{id}", response.Name, response.Version, response.Url); + } + catch (Exception ex) + { + return new ModGenericModel($"{this.VendorKey}:{id}", ex.ToString()); + } + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + this.Client.Dispose(); + } + + + /********* + ** Private models + *********/ + /// A mod metadata response from Nexus Mods. + private class NexusResponseModel + { + /********* + ** Accessors + *********/ + /// The mod name. + public string Name { get; set; } + + /// The mod's semantic version number. + public string Version { get; set; } + + /// The mod's web URL. + [JsonProperty("mod_page_uri")] + public string Url { get; set; } + } + } +} diff --git a/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs b/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs deleted file mode 100644 index 8f010d56..00000000 --- a/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Pathoschild.Http.Client; -using StardewModdingAPI.Web.Models; - -namespace StardewModdingAPI.Web.Framework -{ - /// An HTTP client for fetching mod metadata from Nexus Mods. - internal class NexusModsClient : IModRepository - { - /********* - ** Properties - *********/ - /// The underlying HTTP client. - private readonly IClient Client; - - /********* - ** Public methods - *********/ - /// Construct an instance. - public NexusModsClient() - { - this.Client = new FluentClient("http://www.nexusmods.com/stardewvalley") - .SetUserAgent("Nexus Client v0.63.15"); - } - - /// Get metadata about a mod in the repository. - /// The mod ID in this repository. - public async Task GetModInfoAsync(int id) - { - try - { - NexusResponseModel response = await this.Client - .GetAsync($"mods/{id}") - .As(); - return new ModGenericModel("Nexus", id, response.Name, response.Version, response.Url); - } - catch (Exception) - { - return new ModGenericModel("Nexus", id); - } - } - - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - public void Dispose() - { - this.Client.Dispose(); - } - - - /********* - ** Private models - *********/ - /// A mod metadata response from Nexus Mods. - private class NexusResponseModel - { - /********* - ** Accessors - *********/ - /// The unique mod ID. - public int ID { get; set; } - - /// The mod name. - public string Name { get; set; } - - /// The mod's semantic version number. - public string Version { get; set; } - - /// The mod's web URL. - [JsonProperty("mod_page_uri")] - public string Url { get; set; } - } - } -} diff --git a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs index dc36c7f4..88a6e4bd 100644 --- a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs +++ b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs @@ -1,3 +1,5 @@ +using Newtonsoft.Json; + namespace StardewModdingAPI.Web.Models { /// Generic metadata about a mod. @@ -6,53 +8,48 @@ namespace StardewModdingAPI.Web.Models /********* ** Accessors *********/ - /// The unique mod ID. - public int ID { get; } + /// The namespaced mod key. + public string ModKey { get; } /// The mod name. public string Name { get; } - /// The mod's vendor ID. - public string Vendor { get; } - /// The mod's semantic version number. public string Version { get; } /// The mod's web URL. public string Url { get; } - /// Whether the mod is valid. - public bool Valid { get; } + /// The error message indicating why the mod is invalid (if applicable). + public string Error { get; } /********* ** Public methods *********/ /// Construct a valid instance. - /// The mod's vendor ID. - /// The unique mod ID. + /// The namespaced mod key. /// The mod name. /// The mod's semantic version number. /// The mod's web URL. - /// Whether the mod is valid. - public ModGenericModel(string vendor, int id, string name, string version, string url, bool valid = true) + /// The error message indicating why the mod is invalid (if applicable). + [JsonConstructor] + public ModGenericModel(string modKey, string name, string version, string url, string error = null) { - this.Vendor = vendor; - this.ID = id; + this.ModKey = modKey; this.Name = name; this.Version = version; this.Url = url; - this.Valid = valid; + this.Error = error; // mainly initialised here for the JSON deserialiser } /// Construct an valid instance. - /// The mod's vendor ID. - /// The unique mod ID. - public ModGenericModel(string vendor, int id) + /// The namespaced mod key. + /// The error message indicating why the mod is invalid. + public ModGenericModel(string modKey, string error) { - this.Vendor = vendor; - this.ID = id; - this.Valid = false; + this.ModKey = modKey; + this.Error = error; } } } diff --git a/src/StardewModdingAPI.Web/Models/ModSearchModel.cs b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs index eb9ac920..852ea439 100644 --- a/src/StardewModdingAPI.Web/Models/ModSearchModel.cs +++ b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs @@ -1,9 +1,9 @@ namespace StardewModdingAPI.Web.Models { - /// The search criteria for a mod. + /// The mod update search criteria. public class ModSearchModel { - /// The Nexus Mods ID (if any). - public int? NexusID { get; set; } + /// The namespaced mod keys to search. + public string[] ModKeys { get; set; } } } -- cgit From 9c072333d161d2510ee884d71dc9a714bbf86033 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 22 Sep 2017 00:58:25 -0400 Subject: rename mods endpoint & model (#336) --- .../Controllers/CheckController.cs | 87 ---------------------- .../Controllers/ModsController.cs | 87 ++++++++++++++++++++++ .../Framework/ModRepositories/IModRepository.cs | 2 +- .../Framework/ModRepositories/NexusRepository.cs | 6 +- .../Models/ModGenericModel.cs | 55 -------------- src/StardewModdingAPI.Web/Models/ModInfoModel.cs | 55 ++++++++++++++ 6 files changed, 146 insertions(+), 146 deletions(-) delete mode 100644 src/StardewModdingAPI.Web/Controllers/CheckController.cs create mode 100644 src/StardewModdingAPI.Web/Controllers/ModsController.cs delete mode 100644 src/StardewModdingAPI.Web/Models/ModGenericModel.cs create mode 100644 src/StardewModdingAPI.Web/Models/ModInfoModel.cs (limited to 'src') diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs deleted file mode 100644 index 2a346cf3..00000000 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using StardewModdingAPI.Web.Framework.ModRepositories; -using StardewModdingAPI.Web.Models; - -namespace StardewModdingAPI.Web.Controllers -{ - /// Provides an API to perform mod update checks. - [Produces("application/json")] - [Route("api/check")] - public class CheckController : Controller - { - /********* - ** Properties - *********/ - /// The mod repositories which provide mod metadata. - private readonly IDictionary Repositories = - new IModRepository[] - { - new NexusRepository() - } - .ToDictionary(p => p.VendorKey, StringComparer.CurrentCultureIgnoreCase); - - - /********* - ** Public methods - *********/ - /// Fetch version metadata for the given mods. - /// The mod update search criteria. - [HttpPost] - public async Task Post([FromBody] ModSearchModel search) - { - IList result = new List(); - - foreach (string modKey in search.ModKeys) - { - // parse mod key - if (!this.TryParseModKey(modKey, out string vendorKey, out string modID)) - { - result.Add(new ModGenericModel(modKey, "The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'.")); - continue; - } - - // get matching repository - if (!this.Repositories.TryGetValue(vendorKey, out IModRepository repository)) - { - result.Add(new ModGenericModel(modKey, "There's no mod repository matching this namespaced mod ID.")); - continue; - } - - // fetch mod info - result.Add(await repository.GetModInfoAsync(modID)); - } - - return result.ToArray(); - } - - - /********* - ** Private methods - *********/ - /// Parse a namespaced mod ID. - /// The raw mod ID to parse. - /// The parsed vendor key. - /// The parsed mod ID. - /// Returns whether the value could be parsed. - private bool TryParseModKey(string raw, out string vendorKey, out string modID) - { - // split parts - string[] parts = raw?.Split(':'); - if (parts == null || parts.Length != 2) - { - vendorKey = null; - modID = null; - return false; - } - - // parse - vendorKey = parts[0]; - modID = parts[1]; - return true; - } - } -} diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs new file mode 100644 index 00000000..bbf1744f --- /dev/null +++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using StardewModdingAPI.Web.Framework.ModRepositories; +using StardewModdingAPI.Web.Models; + +namespace StardewModdingAPI.Web.Controllers +{ + /// Provides an API to perform mod update checks. + [Produces("application/json")] + public class ModsController : Controller + { + /********* + ** Properties + *********/ + /// The mod repositories which provide mod metadata. + private readonly IDictionary Repositories = + new IModRepository[] + { + new NexusRepository() + } + .ToDictionary(p => p.VendorKey, StringComparer.CurrentCultureIgnoreCase); + + + /********* + ** Public methods + *********/ + /// Fetch version metadata for the given mods. + /// The mod update search criteria. + [HttpPost] + [Route("mods")] + public async Task Post([FromBody] ModSearchModel search) + { + IList result = new List(); + + foreach (string modKey in search.ModKeys) + { + // parse mod key + if (!this.TryParseModKey(modKey, out string vendorKey, out string modID)) + { + result.Add(new ModInfoModel(modKey, "The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'.")); + continue; + } + + // get matching repository + if (!this.Repositories.TryGetValue(vendorKey, out IModRepository repository)) + { + result.Add(new ModInfoModel(modKey, "There's no mod repository matching this namespaced mod ID.")); + continue; + } + + // fetch mod info + result.Add(await repository.GetModInfoAsync(modID)); + } + + return result.ToArray(); + } + + + /********* + ** Private methods + *********/ + /// Parse a namespaced mod ID. + /// The raw mod ID to parse. + /// The parsed vendor key. + /// The parsed mod ID. + /// Returns whether the value could be parsed. + private bool TryParseModKey(string raw, out string vendorKey, out string modID) + { + // split parts + string[] parts = raw?.Split(':'); + if (parts == null || parts.Length != 2) + { + vendorKey = null; + modID = null; + return false; + } + + // parse + vendorKey = parts[0]; + modID = parts[1]; + return true; + } + } +} diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs index 43bad4e9..7fd735cd 100644 --- a/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs @@ -19,6 +19,6 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories *********/ /// Get metadata about a mod in the repository. /// The mod ID in this repository. - Task GetModInfoAsync(string id); + Task GetModInfoAsync(string id); } } diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs index 37f309da..74eef2ef 100644 --- a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs @@ -35,18 +35,18 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories /// Get metadata about a mod in the repository. /// The mod ID in this repository. - public async Task GetModInfoAsync(string id) + public async Task GetModInfoAsync(string id) { try { NexusResponseModel response = await this.Client .GetAsync($"mods/{id}") .As(); - return new ModGenericModel($"{this.VendorKey}:{id}", response.Name, response.Version, response.Url); + return new ModInfoModel($"{this.VendorKey}:{id}", response.Name, response.Version, response.Url); } catch (Exception ex) { - return new ModGenericModel($"{this.VendorKey}:{id}", ex.ToString()); + return new ModInfoModel($"{this.VendorKey}:{id}", ex.ToString()); } } diff --git a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs b/src/StardewModdingAPI.Web/Models/ModGenericModel.cs deleted file mode 100644 index 88a6e4bd..00000000 --- a/src/StardewModdingAPI.Web/Models/ModGenericModel.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Newtonsoft.Json; - -namespace StardewModdingAPI.Web.Models -{ - /// Generic metadata about a mod. - public class ModGenericModel - { - /********* - ** Accessors - *********/ - /// The namespaced mod key. - public string ModKey { get; } - - /// The mod name. - public string Name { get; } - - /// The mod's semantic version number. - public string Version { get; } - - /// The mod's web URL. - public string Url { get; } - - /// The error message indicating why the mod is invalid (if applicable). - public string Error { get; } - - - /********* - ** Public methods - *********/ - /// Construct a valid instance. - /// The namespaced mod key. - /// The mod name. - /// The mod's semantic version number. - /// The mod's web URL. - /// The error message indicating why the mod is invalid (if applicable). - [JsonConstructor] - public ModGenericModel(string modKey, string name, string version, string url, string error = null) - { - this.ModKey = modKey; - this.Name = name; - this.Version = version; - this.Url = url; - this.Error = error; // mainly initialised here for the JSON deserialiser - } - - /// Construct an valid instance. - /// The namespaced mod key. - /// The error message indicating why the mod is invalid. - public ModGenericModel(string modKey, string error) - { - this.ModKey = modKey; - this.Error = error; - } - } -} diff --git a/src/StardewModdingAPI.Web/Models/ModInfoModel.cs b/src/StardewModdingAPI.Web/Models/ModInfoModel.cs new file mode 100644 index 00000000..723d6c73 --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/ModInfoModel.cs @@ -0,0 +1,55 @@ +using Newtonsoft.Json; + +namespace StardewModdingAPI.Web.Models +{ + /// Generic metadata about a mod. + public class ModInfoModel + { + /********* + ** Accessors + *********/ + /// The namespaced mod key. + public string ModKey { get; } + + /// The mod name.