mirror of https://github.com/ppy/osu
Add API versioning
This commit is contained in:
parent
4889750959
commit
7f4cc221d2
|
@ -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; }
|
||||
|
|
|
@ -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}");
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue