Skip to content

Commit

Permalink
Merge pull request ppy#28349 from bdach/do-not-hardcode-api-version
Browse files Browse the repository at this point in the history
Derive API response version from game version
  • Loading branch information
smoogipoo authored May 29, 2024
2 parents fa1da19 + ab01fa6 commit 0a7336e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion osu.Game/Online/API/APIAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public partial class APIAccess : Component, IAPIProvider

public string WebsiteRootUrl { get; }

public int APIVersion => 20220705; // We may want to pull this from the game version eventually.
/// <summary>
/// The API response version.
/// See: https://osu.ppy.sh/docs/index.html#api-versions
/// </summary>
public int APIVersion { get; }

public Exception LastLoginError { get; private set; }

Expand Down Expand Up @@ -84,12 +88,23 @@ public APIAccess(OsuGameBase game, OsuConfigManager config, EndpointConfiguratio
this.config = config;
this.versionHash = versionHash;

if (game.IsDeployedBuild)
APIVersion = game.AssemblyVersion.Major * 10000 + game.AssemblyVersion.Minor;
else
{
var now = DateTimeOffset.Now;
APIVersion = now.Year * 10000 + now.Month * 100 + now.Day;
}

APIEndpointUrl = endpointConfiguration.APIEndpointUrl;
WebsiteRootUrl = endpointConfiguration.WebsiteRootUrl;
NotificationsClient = setUpNotificationsClient();

authentication = new OAuth(endpointConfiguration.APIClientID, endpointConfiguration.APIClientSecret, APIEndpointUrl);

log = Logger.GetLogger(LoggingTarget.Network);
log.Add($@"API endpoint root: {APIEndpointUrl}");
log.Add($@"API request version: {APIVersion}");

ProvidedUsername = config.Get<string>(OsuSetting.Username);

Expand Down

0 comments on commit 0a7336e

Please sign in to comment.