Add API versioning

This commit is contained in:
Dean Herbert 2022-02-17 18:33:27 +09:00
parent 4889750959
commit 7f4cc221d2
4 changed files with 13 additions and 0 deletions

View File

@ -36,6 +36,8 @@ public class APIAccess : Component, IAPIProvider
public string WebsiteRootUrl { get; }
public int APIVersion => 20220217; // We may want to pull this from the game version eventually.
public Exception LastLoginError { get; private set; }
public string ProvidedUsername { get; private set; }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Globalization;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.IO.Network;
@ -112,6 +113,9 @@ public void Perform(IAPIProvider api)
WebRequest = CreateWebRequest();
WebRequest.Failed += Fail;
WebRequest.AllowRetryOnTimeout = false;
WebRequest.AddHeader("x-api-version", API.APIVersion.ToString(CultureInfo.InvariantCulture));
if (!string.IsNullOrEmpty(API.AccessToken))
WebRequest.AddHeader("Authorization", $"Bearer {API.AccessToken}");

View File

@ -33,6 +33,8 @@ public class DummyAPIAccess : Component, IAPIProvider
public string WebsiteRootUrl => "http://localhost";
public int APIVersion => int.Parse(DateTime.Now.ToString("yyyyMMdd"));
public Exception LastLoginError { get; private set; }
/// <summary>

View File

@ -57,6 +57,11 @@ public interface IAPIProvider
/// </summary>
string WebsiteRootUrl { get; }
/// <summary>
/// The version of the API.
/// </summary>
int APIVersion { get; }
/// <summary>
/// The last login error that occurred, if any.
/// </summary>