1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 09:47:24 +08:00

add API model and request

This commit is contained in:
cdwcgt 2024-11-01 12:52:37 +08:00
parent 9872097513
commit bf53833b7b
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
4 changed files with 87 additions and 1 deletions

View 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";
}
}

View 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}";
}
}

View File

@ -6,7 +6,7 @@ using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetFriendsRequest : APIRequest<List<APIUser>>
public class GetFriendsRequest : APIRequest<List<APIRelation>>
{
protected override string Target => @"friends";
}

View 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,
}
}