mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 15:17:44 +08:00
add API model and request
This commit is contained in:
parent
9872097513
commit
bf53833b7b
31
osu.Game/Online/API/Requests/FriendAddRequest.cs
Normal file
31
osu.Game/Online/API/Requests/FriendAddRequest.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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 System.Net.Http;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class FriendAddRequest : APIRequest<APIRelation>
|
||||||
|
{
|
||||||
|
private readonly int targetId;
|
||||||
|
|
||||||
|
public FriendAddRequest(int targetId)
|
||||||
|
{
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
req.Method = HttpMethod.Post;
|
||||||
|
req.AddParameter("target", targetId.ToString(), RequestParameterType.Query);
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => @"friends";
|
||||||
|
}
|
||||||
|
}
|
27
osu.Game/Online/API/Requests/FriendDeleteRequest.cs
Normal file
27
osu.Game/Online/API/Requests/FriendDeleteRequest.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// 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 System.Net.Http;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class FriendDeleteRequest : APIRequest
|
||||||
|
{
|
||||||
|
private readonly int targetId;
|
||||||
|
|
||||||
|
public FriendDeleteRequest(int targetId)
|
||||||
|
{
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
req.Method = HttpMethod.Delete;
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $@"friends/{targetId}";
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using osu.Game.Online.API.Requests.Responses;
|
|||||||
|
|
||||||
namespace osu.Game.Online.API.Requests
|
namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
public class GetFriendsRequest : APIRequest<List<APIUser>>
|
public class GetFriendsRequest : APIRequest<List<APIRelation>>
|
||||||
{
|
{
|
||||||
protected override string Target => @"friends";
|
protected override string Target => @"friends";
|
||||||
}
|
}
|
||||||
|
28
osu.Game/Online/API/Requests/Responses/APIRelation.cs
Normal file
28
osu.Game/Online/API/Requests/Responses/APIRelation.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 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 Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
|
{
|
||||||
|
public class APIRelation
|
||||||
|
{
|
||||||
|
[JsonProperty("target_id")]
|
||||||
|
public int TargetID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("relation_type")]
|
||||||
|
public RelationType RelationType { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("mutual")]
|
||||||
|
public bool Mutual { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("target")]
|
||||||
|
public APIUser? TargetUser { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum RelationType
|
||||||
|
{
|
||||||
|
Friend,
|
||||||
|
Block,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user