mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 15:27:20 +08:00
Split /me
request from /users
requests
Them being together always bothered me and led to the abject failure that is `APIUser` and its sprawl. Now that I'm about to add a flag that is unique to `/me` for verification purposes, I'm not repeating the errors of the past by adding yet another flag to `APIUser` that is never present outside of a single usage context.
This commit is contained in:
parent
7c140408ea
commit
7b47215657
@ -266,7 +266,7 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
var userReq = new GetUserRequest();
|
||||
var userReq = new GetMeRequest();
|
||||
userReq.Failure += ex =>
|
||||
{
|
||||
if (ex is APIException)
|
||||
|
24
osu.Game/Online/API/Requests/GetMeRequest.cs
Normal file
24
osu.Game/Online/API/Requests/GetMeRequest.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetMeRequest : APIRequest<APIMe>
|
||||
{
|
||||
public readonly IRulesetInfo? Ruleset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently logged-in user.
|
||||
/// </summary>
|
||||
/// <param name="ruleset">The ruleset to get the user's info for.</param>
|
||||
public GetMeRequest(IRulesetInfo? ruleset = null)
|
||||
{
|
||||
Ruleset = ruleset;
|
||||
}
|
||||
|
||||
protected override string Target => $@"me/{Ruleset?.ShortName}";
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
@ -11,24 +9,17 @@ namespace osu.Game.Online.API.Requests
|
||||
public class GetUserRequest : APIRequest<APIUser>
|
||||
{
|
||||
public readonly string Lookup;
|
||||
public readonly IRulesetInfo Ruleset;
|
||||
public readonly IRulesetInfo? Ruleset;
|
||||
private readonly LookupType lookupType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently logged-in user.
|
||||
/// </summary>
|
||||
public GetUserRequest()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a user from their ID.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user to get.</param>
|
||||
/// <param name="ruleset">The ruleset to get the user's info for.</param>
|
||||
public GetUserRequest(long? userId = null, IRulesetInfo ruleset = null)
|
||||
public GetUserRequest(long? userId = null, IRulesetInfo? ruleset = null)
|
||||
{
|
||||
Lookup = userId.ToString();
|
||||
Lookup = userId.ToString()!;
|
||||
lookupType = LookupType.Id;
|
||||
Ruleset = ruleset;
|
||||
}
|
||||
@ -38,14 +29,14 @@ namespace osu.Game.Online.API.Requests
|
||||
/// </summary>
|
||||
/// <param name="username">The user to get.</param>
|
||||
/// <param name="ruleset">The ruleset to get the user's info for.</param>
|
||||
public GetUserRequest(string username = null, IRulesetInfo ruleset = null)
|
||||
public GetUserRequest(string username, IRulesetInfo? ruleset = null)
|
||||
{
|
||||
Lookup = username;
|
||||
lookupType = LookupType.Username;
|
||||
Ruleset = ruleset;
|
||||
}
|
||||
|
||||
protected override string Target => Lookup != null ? $@"users/{Lookup}/{Ruleset?.ShortName}?key={lookupType.ToString().ToLowerInvariant()}" : $@"me/{Ruleset?.ShortName}";
|
||||
protected override string Target => $@"users/{Lookup}/{Ruleset?.ShortName}?key={lookupType.ToString().ToLowerInvariant()}";
|
||||
|
||||
private enum LookupType
|
||||
{
|
||||
|
9
osu.Game/Online/API/Requests/Responses/APIMe.cs
Normal file
9
osu.Game/Online/API/Requests/Responses/APIMe.cs
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class APIMe : APIUser
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user