Expand requests

This commit is contained in:
Andrei Zavatski
2019-08-06 17:47:31 +03:00
parent e3f88a83a0
commit 3cfbbac5dc
2 changed files with 20 additions and 3 deletions

View File

@ -2,18 +2,21 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
public class GetUserRequest : APIRequest<User> public class GetUserRequest : APIRequest<User>
{ {
private readonly long? userId; private readonly long? userId;
private readonly RulesetInfo ruleset;
public GetUserRequest(long? userId = null) public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
{ {
this.userId = userId; this.userId = userId;
this.ruleset = ruleset;
} }
protected override string Target => userId.HasValue ? $@"users/{userId}" : @"me"; protected override string Target => userId.HasValue ? (ruleset != null ? $@"users/{userId}/{ruleset.ShortName}" : $@"users/{userId}") : @"me";
} }
} }

View File

@ -2,7 +2,9 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.IO.Network;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
@ -10,12 +12,24 @@ namespace osu.Game.Online.API.Requests
{ {
private readonly long userId; private readonly long userId;
private readonly ScoreType type; private readonly ScoreType type;
private readonly RulesetInfo ruleset;
public GetUserScoresRequest(long userId, ScoreType type, int page = 0, int itemsPerPage = 5) public GetUserScoresRequest(long userId, ScoreType type, int page = 0, int itemsPerPage = 5, RulesetInfo ruleset = null)
: base(page, itemsPerPage) : base(page, itemsPerPage)
{ {
this.userId = userId; this.userId = userId;
this.type = type; this.type = type;
this.ruleset = ruleset;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
if (ruleset != null)
req.AddParameter("mode", ruleset.ShortName);
return req;
} }
protected override string Target => $@"users/{userId}/scores/{type.ToString().ToLowerInvariant()}"; protected override string Target => $@"users/{userId}/scores/{type.ToString().ToLowerInvariant()}";