You've already forked CC-Framework.BriskGameServer
Add package sync workflow
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public sealed class BriskSpaceModule
|
||||
: BriskModuleBase
|
||||
{
|
||||
public async Task<BriskSpaceView> GetByPlayerIdAsync(string playerId)
|
||||
{
|
||||
ValidatePlayerId(playerId);
|
||||
|
||||
return await ExecuteAsync(async context =>
|
||||
{
|
||||
var data = await context.HttpClient.GetDataAsync($"/spaces/{playerId}", null, true);
|
||||
return BriskModelMapper.ToSpaceView(data);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<BriskSpaceView> GetByLoginIdentityAsync(string loginProvider, string loginUserId)
|
||||
{
|
||||
ValidateLoginIdentity(loginProvider, loginUserId);
|
||||
|
||||
return await ExecuteAsync(async context =>
|
||||
{
|
||||
var data = await context.HttpClient.GetDataAsync("/spaces/by-login", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
||||
return BriskModelMapper.ToSpaceView(data);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<BriskSpaceStats> GetStatsByPlayerIdAsync(string playerId)
|
||||
{
|
||||
ValidatePlayerId(playerId);
|
||||
|
||||
return await ExecuteAsync(async context =>
|
||||
{
|
||||
var data = await context.HttpClient.GetDataAsync($"/spaces/{playerId}/stats", null, true);
|
||||
return BriskModelMapper.ToSpaceStats(data);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<BriskSpaceStats> GetStatsByLoginIdentityAsync(string loginProvider, string loginUserId)
|
||||
{
|
||||
ValidateLoginIdentity(loginProvider, loginUserId);
|
||||
|
||||
return await ExecuteAsync(async context =>
|
||||
{
|
||||
var data = await context.HttpClient.GetDataAsync("/spaces/by-login/stats", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
||||
return BriskModelMapper.ToSpaceStats(data);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task LikeByPlayerIdAsync(string playerId)
|
||||
{
|
||||
ValidatePlayerId(playerId);
|
||||
await ExecuteAsync(async context =>
|
||||
{
|
||||
await context.HttpClient.PostJsonRawAsync($"/spaces/{playerId}/like", new Dictionary<string, object>(), true);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UnlikeByPlayerIdAsync(string playerId)
|
||||
{
|
||||
ValidatePlayerId(playerId);
|
||||
await ExecuteAsync(async context =>
|
||||
{
|
||||
await context.HttpClient.SendDeleteJsonRawAsync($"/spaces/{playerId}/like", null, true);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task LikeByLoginIdentityAsync(string loginProvider, string loginUserId)
|
||||
{
|
||||
ValidateLoginIdentity(loginProvider, loginUserId);
|
||||
await ExecuteAsync(async context =>
|
||||
{
|
||||
await context.HttpClient.PostJsonRawAsync("/spaces/by-login/like", new Dictionary<string, object>(), true, CreateLoginIdentityQuery(loginProvider, loginUserId));
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UnlikeByLoginIdentityAsync(string loginProvider, string loginUserId)
|
||||
{
|
||||
ValidateLoginIdentity(loginProvider, loginUserId);
|
||||
await ExecuteAsync(async context =>
|
||||
{
|
||||
await context.HttpClient.SendDeleteJsonRawAsync("/spaces/by-login/like", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UpdateMyAsync(object payload)
|
||||
{
|
||||
RequireNotNull(payload, nameof(payload));
|
||||
|
||||
await ExecuteAsync(async context =>
|
||||
{
|
||||
await context.HttpClient.SendPutJsonRawAsync(
|
||||
"/spaces/me",
|
||||
new Dictionary<string, object> { { "payload_json", payload } },
|
||||
true);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<BriskSpaceVisit>> GetMyVisitsAsync()
|
||||
{
|
||||
return await ExecuteAsync(async context =>
|
||||
{
|
||||
var data = await context.HttpClient.GetRawDataAsync("/spaces/me/visits", null, true);
|
||||
return (IReadOnlyList<BriskSpaceVisit>)BriskModelMapper.ToSpaceVisits(data);
|
||||
});
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> CreateLoginIdentityQuery(string loginProvider, string loginUserId)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ "login_provider", loginProvider },
|
||||
{ "login_user_id", loginUserId }
|
||||
};
|
||||
}
|
||||
|
||||
private static void ValidatePlayerId(string playerId)
|
||||
{
|
||||
RequireNotEmpty(playerId, nameof(playerId));
|
||||
}
|
||||
|
||||
private static void ValidateLoginIdentity(string loginProvider, string loginUserId)
|
||||
{
|
||||
RequireNotEmpty(loginProvider, nameof(loginProvider));
|
||||
RequireNotEmpty(loginUserId, nameof(loginUserId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user