summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs')
-rw-r--r--src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs51
1 files changed, 10 insertions, 41 deletions
diff --git a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
index 8a4bb0d8..cfa757ab 100644
--- a/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
+++ b/src/SMAPI.Web/Framework/ModRepositories/NexusRepository.cs
@@ -1,8 +1,7 @@
using System;
using System.Threading.Tasks;
-using Newtonsoft.Json;
-using Pathoschild.Http.Client;
using StardewModdingAPI.Common.Models;
+using StardewModdingAPI.Web.Framework.Clients.Nexus;
namespace StardewModdingAPI.Web.Framework.ModRepositories
{
@@ -12,11 +11,8 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/*********
** Properties
*********/
- /// <summary>The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID.</summary>
- private readonly string ModUrlFormat;
-
- /// <summary>The underlying HTTP client.</summary>
- private readonly IClient Client;
+ /// <summary>The underlying Nexus Mods API client.</summary>
+ private readonly INexusClient Client;
/*********
@@ -24,14 +20,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
*********/
/// <summary>Construct an instance.</summary>
/// <param name="vendorKey">The unique key for this vendor.</param>
- /// <param name="userAgent">The user agent for the Nexus Mods API client.</param>
- /// <param name="baseUrl">The base URL for the Nexus Mods API.</param>
- /// <param name="modUrlFormat">The URL for a Nexus Mods API query excluding the <paramref name="baseUrl"/>, where {0} is the mod ID.</param>
- public NexusRepository(string vendorKey, string userAgent, string baseUrl, string modUrlFormat)
+ /// <param name="client">The underlying Nexus Mods API client.</param>
+ public NexusRepository(string vendorKey, INexusClient client)
: base(vendorKey)
{
- this.ModUrlFormat = modUrlFormat;
- this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent);
+ this.Client = client;
}
/// <summary>Get metadata about a mod in the repository.</summary>
@@ -39,18 +32,15 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
// validate ID format
- if (!uint.TryParse(id, out uint _))
+ if (!uint.TryParse(id, out uint nexusID))
return new ModInfoModel($"The value '{id}' isn't a valid Nexus mod ID, must be an integer ID.");
// fetch info
try
{
- NexusResponseModel response = await this.Client
- .GetAsync(string.Format(this.ModUrlFormat, id))
- .As<NexusResponseModel>();
-
- return response != null
- ? new ModInfoModel(response.Name, this.NormaliseVersion(response.Version), response.Url)
+ NexusMod mod = await this.Client.GetModAsync(nexusID);
+ return mod != null
+ ? new ModInfoModel(mod.Name, this.NormaliseVersion(mod.Version), mod.Url)
: new ModInfoModel("Found no mod with this ID.");
}
catch (Exception ex)
@@ -64,26 +54,5 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
{
this.Client.Dispose();
}
-
-
- /*********
- ** Private models
- *********/
- /// <summary>A mod metadata response from Nexus Mods.</summary>
- private class NexusResponseModel
- {
- /*********
- ** Accessors
- *********/
- /// <summary>The mod name.</summary>
- public string Name { get; set; }
-
- /// <summary>The mod's semantic version number.</summary>
- public string Version { get; set; }
-
- /// <summary>The mod's web URL.</summary>
- [JsonProperty("mod_page_uri")]
- public string Url { get; set; }
- }
}
}