summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/ModRepositories
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-07 13:40:44 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-07 13:40:44 -0500
commita78b1935928919694dfe8de823a1accd6d222732 (patch)
tree3f17b6087cf2749e52c1e237de17e2e9addb6c06 /src/SMAPI.Web/Framework/ModRepositories
parent4cd9eda1591c3908bf80b60c2902491a7595ee27 (diff)
parent8901218418693d610a17b22fe789ba6279f63446 (diff)
downloadSMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.gz
SMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.bz2
SMAPI-a78b1935928919694dfe8de823a1accd6d222732.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Web/Framework/ModRepositories')
-rw-r--r--src/SMAPI.Web/Framework/ModRepositories/ModDropRepository.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/SMAPI.Web/Framework/ModRepositories/ModDropRepository.cs b/src/SMAPI.Web/Framework/ModRepositories/ModDropRepository.cs
new file mode 100644
index 00000000..09484aa8
--- /dev/null
+++ b/src/SMAPI.Web/Framework/ModRepositories/ModDropRepository.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Threading.Tasks;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
+using StardewModdingAPI.Web.Framework.Clients.ModDrop;
+
+namespace StardewModdingAPI.Web.Framework.ModRepositories
+{
+ /// <summary>An HTTP client for fetching mod metadata from the ModDrop API.</summary>
+ internal class ModDropRepository : RepositoryBase
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The underlying ModDrop API client.</summary>
+ private readonly IModDropClient Client;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="client">The underlying Nexus Mods API client.</param>
+ public ModDropRepository(IModDropClient client)
+ : base(ModRepositoryKey.ModDrop)
+ {
+ this.Client = client;
+ }
+
+ /// <summary>Get metadata about a mod in the repository.</summary>
+ /// <param name="id">The mod ID in this repository.</param>
+ public override async Task<ModInfoModel> GetModInfoAsync(string id)
+ {
+ // validate ID format
+ if (!long.TryParse(id, out long modDropID))
+ return new ModInfoModel($"The value '{id}' isn't a valid ModDrop mod ID, must be an integer ID.");
+
+ // fetch info
+ try
+ {
+ ModDropMod mod = await this.Client.GetModAsync(modDropID);
+ if (mod == null)
+ return new ModInfoModel("Found no mod with this ID.");
+ if (mod.Error != null)
+ return new ModInfoModel(mod.Error);
+ return new ModInfoModel(name: mod.Name, version: mod.LatestDefaultVersion?.ToString(), previewVersion: mod.LatestOptionalVersion?.ToString(), url: mod.Url);
+ }
+ catch (Exception ex)
+ {
+ return new ModInfoModel(ex.ToString());
+ }
+ }
+
+ /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
+ public override void Dispose()
+ {
+ this.Client.Dispose();
+ }
+ }
+}