summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-24 13:19:02 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-24 13:19:02 -0400
commit9b247b67f64af903fd610481e74dbe7175580b84 (patch)
tree117bafa8fb1c9980ca688c6abdf220ea1f323a49 /src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
parent96acccad7c57b005f73fbe6aad30291c7fbb633d (diff)
downloadSMAPI-9b247b67f64af903fd610481e74dbe7175580b84.tar.gz
SMAPI-9b247b67f64af903fd610481e74dbe7175580b84.tar.bz2
SMAPI-9b247b67f64af903fd610481e74dbe7175580b84.zip
improve version normalising (#336, #361)
Diffstat (limited to 'src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs')
-rw-r--r--src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
index f794c605..7dfe9f62 100644
--- a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
+++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
@@ -7,26 +7,19 @@ using StardewModdingAPI.Models;
namespace StardewModdingAPI.Web.Framework.ModRepositories
{
/// <summary>An HTTP client for fetching mod metadata from GitHub project releases.</summary>
- internal class GitHubRepository : IModRepository
+ internal class GitHubRepository : RepositoryBase
{
/*********
** Properties
*********/
+ /// <summary>The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID.</summary>
+ private readonly string ReleaseUrlFormat;
+
/// <summary>The underlying HTTP client.</summary>
private readonly IClient Client;
/*********
- ** Accessors
- *********/
- /// <summary>The unique key for this vendor.</summary>
- public string VendorKey { get; }
-
- /// <summary>The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID.</summary>
- public string ReleaseUrlFormat { get; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -38,8 +31,8 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <param name="username">The username with which to authenticate to the GitHub API.</param>
/// <param name="password">The password with which to authenticate to the GitHub API.</param>
public GitHubRepository(string vendorKey, string baseUrl, string releaseUrlFormat, string userAgent, string acceptHeader, string username, string password)
+ : base(vendorKey)
{
- this.VendorKey = vendorKey;
this.ReleaseUrlFormat = releaseUrlFormat;
this.Client = new FluentClient(baseUrl)
@@ -51,23 +44,14 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <summary>Get metadata about a mod in the repository.</summary>
/// <param name="id">The mod ID in this repository.</param>
- public async Task<ModInfoModel> GetModInfoAsync(string id)
+ public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
try
{
- // fetch data
GitRelease release = await this.Client
.GetAsync(string.Format(this.ReleaseUrlFormat, id))
.As<GitRelease>();
-
- // extract fields
- string name = id;
- string version = release.Tag;
- if (version.StartsWith("v")) // common format on GitHub
- version = version.Substring(1);
- string url = $"https://github.com/{id}/releases";
-
- return new ModInfoModel(name, version, url);
+ return new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases");
}
catch (Exception ex)
{
@@ -76,7 +60,7 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
- public void Dispose()
+ public override void Dispose()
{
this.Client.Dispose();
}