diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-22 00:47:46 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-22 00:47:46 -0400 |
commit | 2c02dfe45a6d1252bfef557db8f39f97e57d3d19 (patch) | |
tree | 4fb8b5759d56ba6a62a452e09180ede280228b3b /src/StardewModdingAPI.Web/Framework | |
parent | edbc3ef3c08909486d6c4b8797f0e3c2934854fa (diff) | |
download | SMAPI-2c02dfe45a6d1252bfef557db8f39f97e57d3d19.tar.gz SMAPI-2c02dfe45a6d1252bfef557db8f39f97e57d3d19.tar.bz2 SMAPI-2c02dfe45a6d1252bfef557db8f39f97e57d3d19.zip |
rewrite to make update-check logic vendor-agnostic (#336)
Diffstat (limited to 'src/StardewModdingAPI.Web/Framework')
-rw-r--r-- | src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs (renamed from src/StardewModdingAPI.Web/Framework/IModRepository.cs) | 11 | ||||
-rw-r--r-- | src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs (renamed from src/StardewModdingAPI.Web/Framework/NexusModsClient.cs) | 25 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/StardewModdingAPI.Web/Framework/IModRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs index ebf9850f..43bad4e9 100644 --- a/src/StardewModdingAPI.Web/Framework/IModRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/IModRepository.cs @@ -2,16 +2,23 @@ using System; using System.Threading.Tasks; using StardewModdingAPI.Web.Models; -namespace StardewModdingAPI.Web.Framework +namespace StardewModdingAPI.Web.Framework.ModRepositories { /// <summary>A repository which provides mod metadata.</summary> internal interface IModRepository : IDisposable { /********* + ** Accessors + *********/ + /// <summary>The unique key for this vendor.</summary> + string VendorKey { get; } + + + /********* ** Public methods *********/ /// <summary>Get metadata about a mod in the repository.</summary> /// <param name="id">The mod ID in this repository.</param> - Task<ModGenericModel> GetModInfoAsync(int id); + Task<ModGenericModel> GetModInfoAsync(string id); } } diff --git a/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs index 8f010d56..37f309da 100644 --- a/src/StardewModdingAPI.Web/Framework/NexusModsClient.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs @@ -4,10 +4,10 @@ using Newtonsoft.Json; using Pathoschild.Http.Client; using StardewModdingAPI.Web.Models; -namespace StardewModdingAPI.Web.Framework +namespace StardewModdingAPI.Web.Framework.ModRepositories { /// <summary>An HTTP client for fetching mod metadata from Nexus Mods.</summary> - internal class NexusModsClient : IModRepository + internal class NexusRepository : IModRepository { /********* ** Properties @@ -15,11 +15,19 @@ namespace StardewModdingAPI.Web.Framework /// <summary>The underlying HTTP client.</summary> private readonly IClient Client; + + /********* + ** Accessors + *********/ + /// <summary>The unique key for this vendor.</summary> + public string VendorKey { get; } = "Nexus"; + + /********* ** Public methods *********/ /// <summary>Construct an instance.</summary> - public NexusModsClient() + public NexusRepository() { this.Client = new FluentClient("http://www.nexusmods.com/stardewvalley") .SetUserAgent("Nexus Client v0.63.15"); @@ -27,18 +35,18 @@ namespace StardewModdingAPI.Web.Framework /// <summary>Get metadata about a mod in the repository.</summary> /// <param name="id">The mod ID in this repository.</param> - public async Task<ModGenericModel> GetModInfoAsync(int id) + public async Task<ModGenericModel> GetModInfoAsync(string id) { try { NexusResponseModel response = await this.Client .GetAsync($"mods/{id}") .As<NexusResponseModel>(); - return new ModGenericModel("Nexus", id, response.Name, response.Version, response.Url); + return new ModGenericModel($"{this.VendorKey}:{id}", response.Name, response.Version, response.Url); } - catch (Exception) + catch (Exception ex) { - return new ModGenericModel("Nexus", id); + return new ModGenericModel($"{this.VendorKey}:{id}", ex.ToString()); } } @@ -58,9 +66,6 @@ namespace StardewModdingAPI.Web.Framework /********* ** Accessors *********/ - /// <summary>The unique mod ID.</summary> - public int ID { get; set; } - /// <summary>The mod name.</summary> public string Name { get; set; } |