Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Runtime/Api/AsobiDirectMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
{
public class AsobiDirectMessages
{
readonly AsobiClient _client;
internal AsobiDirectMessages(AsobiClient client) => _client = client;

public Task<DmSendResponse> SendAsync(string recipientId, string content)
{
var req = new SendDmRequest { recipient_id = recipientId, content = content };
return _client.Http.Post<DmSendResponse>("/api/v1/dm", req);
}

public Task<DirectMessageListResponse> GetHistoryAsync(string playerId, int limit = 50)
{
var query = new Dictionary<string, string> { { "limit", limit.ToString() } };
return _client.Http.Get<DirectMessageListResponse>($"/api/v1/dm/{playerId}/history", query);
}
}
}
12 changes: 8 additions & 4 deletions Runtime/Api/AsobiInventory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
Expand All @@ -7,15 +8,18 @@ public class AsobiInventory
readonly AsobiClient _client;
internal AsobiInventory(AsobiClient client) => _client = client;

public Task<InventoryResponse> ListAsync()
public Task<InventoryResponse> ListAsync(int? limit = null)
{
return _client.Http.Get<InventoryResponse>("/api/v1/inventory");
Dictionary<string, string> query = null;
if (limit.HasValue)
query = new Dictionary<string, string> { { "limit", limit.Value.ToString() } };
return _client.Http.Get<InventoryResponse>("/api/v1/inventory", query);
}

public Task<AsobiResponse> ConsumeAsync(string itemId, int quantity = 1)
public Task<ConsumeResponse> ConsumeAsync(string itemId, int quantity = 1)
{
var req = new ConsumeRequest { item_id = itemId, quantity = quantity };
return _client.Http.Post<AsobiResponse>("/api/v1/inventory/consume", req);
return _client.Http.Post<ConsumeResponse>("/api/v1/inventory/consume", req);
}
}
}
13 changes: 11 additions & 2 deletions Runtime/Api/AsobiMatches.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
Expand All @@ -7,9 +8,17 @@ public class AsobiMatches
readonly AsobiClient _client;
internal AsobiMatches(AsobiClient client) => _client = client;

public async Task<MatchListResponse> ListAsync()
public async Task<MatchListResponse> ListAsync(string mode = null, string status = null, int? limit = null)
{
var raw = await _client.Http.GetRaw("/api/v1/matches");
Dictionary<string, string> query = null;
if (mode != null || status != null || limit.HasValue)
{
query = new Dictionary<string, string>();
if (mode != null) query["mode"] = mode;
if (status != null) query["status"] = status;
if (limit.HasValue) query["limit"] = limit.Value.ToString();
}
var raw = await _client.Http.GetRaw("/api/v1/matches", query);
return JsonHelper.ParseMatchList(raw);
}

Expand Down
4 changes: 2 additions & 2 deletions Runtime/Api/AsobiMatchmaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class AsobiMatchmaker
readonly AsobiClient _client;
internal AsobiMatchmaker(AsobiClient client) => _client = client;

public Task<MatchmakerTicket> AddAsync(string mode = "default")
public Task<MatchmakerTicket> AddAsync(string mode = "default", string properties = null, string[] party = null)
{
var req = new MatchmakerRequest { mode = mode };
var req = new MatchmakerRequest { mode = mode, properties = properties, party = party };
return _client.Http.Post<MatchmakerTicket>("/api/v1/matchmaker", req);
}

Expand Down
17 changes: 13 additions & 4 deletions Runtime/Api/AsobiNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
Expand All @@ -7,15 +8,23 @@ public class AsobiNotifications
readonly AsobiClient _client;
internal AsobiNotifications(AsobiClient client) => _client = client;

public async Task<NotificationListResponse> ListAsync()
public async Task<NotificationListResponse> ListAsync(bool? read = null, int? limit = null)
{
var raw = await _client.Http.GetRaw("/api/v1/notifications");
Dictionary<string, string> query = null;
if (read.HasValue || limit.HasValue)
{
query = new Dictionary<string, string>();
if (read.HasValue) query["read"] = read.Value.ToString().ToLower();
if (limit.HasValue) query["limit"] = limit.Value.ToString();
}
var raw = await _client.Http.GetRaw("/api/v1/notifications", query);
return JsonHelper.ParseNotificationList(raw);
}

public Task<AsobiResponse> MarkReadAsync(string notificationId)
public async Task<Notification> MarkReadAsync(string notificationId)
{
return _client.Http.Put<AsobiResponse>($"/api/v1/notifications/{notificationId}/read");
var raw = await _client.Http.PutRaw($"/api/v1/notifications/{notificationId}/read", "{}");
return JsonHelper.ParseNotification(raw);
}

public Task<AsobiResponse> DeleteAsync(string notificationId)
Expand Down
40 changes: 34 additions & 6 deletions Runtime/Api/AsobiSocial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ public Task<Friendship> AddFriendAsync(string friendId)
return _client.Http.Post<Friendship>("/api/v1/friends", req);
}

public Task<Friendship> AcceptFriendAsync(string friendId)
public Task<Friendship> UpdateFriendAsync(string friendId, string status)
{
var req = new UpdateFriendRequest { status = "accepted" };
var req = new UpdateFriendRequest { status = status };
return _client.Http.Put<Friendship>($"/api/v1/friends/{friendId}", req);
}

public Task<Friendship> AcceptFriendAsync(string friendId)
{
return UpdateFriendAsync(friendId, "accepted");
}

public Task<Friendship> BlockFriendAsync(string friendId)
{
var req = new UpdateFriendRequest { status = "blocked" };
return _client.Http.Put<Friendship>($"/api/v1/friends/{friendId}", req);
return UpdateFriendAsync(friendId, "blocked");
}

public Task<AsobiResponse> RemoveFriendAsync(string friendId)
Expand Down Expand Up @@ -65,16 +69,40 @@ public Task<AsobiResponse> JoinGroupAsync(string groupId)
return _client.Http.Post<AsobiResponse>($"/api/v1/groups/{groupId}/join");
}

public Task<Group> UpdateGroupAsync(string groupId, UpdateGroupRequest update)
{
return _client.Http.Put<Group>($"/api/v1/groups/{groupId}", update);
}

public Task<AsobiResponse> LeaveGroupAsync(string groupId)
{
return _client.Http.Post<AsobiResponse>($"/api/v1/groups/{groupId}/leave");
}

public Task<GroupMembersResponse> GetGroupMembersAsync(string groupId)
{
return _client.Http.Get<GroupMembersResponse>($"/api/v1/groups/{groupId}/members");
}

public Task<GroupMember> UpdateMemberRoleAsync(string groupId, string playerId, string role)
{
var req = new UpdateMemberRoleRequest { role = role };
return _client.Http.Put<GroupMember>($"/api/v1/groups/{groupId}/members/{playerId}/role", req);
}

public Task<AsobiResponse> RemoveMemberAsync(string groupId, string playerId)
{
return _client.Http.Delete($"/api/v1/groups/{groupId}/members/{playerId}");
}

// --- Chat ---

public Task<ChatHistoryResponse> GetChatHistoryAsync(string channelId)
public Task<ChatHistoryResponse> GetChatHistoryAsync(string channelId, int? limit = null)
{
return _client.Http.Get<ChatHistoryResponse>($"/api/v1/chat/{channelId}/history");
Dictionary<string, string> query = null;
if (limit.HasValue)
query = new Dictionary<string, string> { { "limit", limit.Value.ToString() } };
return _client.Http.Get<ChatHistoryResponse>($"/api/v1/chat/{channelId}/history", query);
}
}
}
12 changes: 10 additions & 2 deletions Runtime/Api/AsobiTournaments.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
Expand All @@ -7,9 +8,16 @@ public class AsobiTournaments
readonly AsobiClient _client;
internal AsobiTournaments(AsobiClient client) => _client = client;

public Task<TournamentListResponse> ListAsync()
public Task<TournamentListResponse> ListAsync(string status = null, int? limit = null)
{
return _client.Http.Get<TournamentListResponse>("/api/v1/tournaments");
Dictionary<string, string> query = null;
if (status != null || limit.HasValue)
{
query = new Dictionary<string, string>();
if (status != null) query["status"] = status;
if (limit.HasValue) query["limit"] = limit.Value.ToString();
}
return _client.Http.Get<TournamentListResponse>("/api/v1/tournaments", query);
}

public Task<Tournament> GetAsync(string tournamentId)
Expand Down
36 changes: 36 additions & 0 deletions Runtime/Api/AsobiWorlds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Asobi
{
public class AsobiWorlds
{
readonly AsobiClient _client;
internal AsobiWorlds(AsobiClient client) => _client = client;

public Task<WorldListResponse> ListAsync(string mode = null, bool? hasCapacity = null)
{
Dictionary<string, string> query = null;
if (mode != null || hasCapacity.HasValue)
{
query = new Dictionary<string, string>();
if (mode != null)
query["mode"] = mode;
if (hasCapacity.HasValue)
query["has_capacity"] = hasCapacity.Value.ToString().ToLower();
}
return _client.Http.Get<WorldListResponse>("/api/v1/worlds", query);
}

public Task<WorldInfo> GetAsync(string worldId)
{
return _client.Http.Get<WorldInfo>($"/api/v1/worlds/{worldId}");
}

public Task<WorldInfo> CreateAsync(string mode)
{
var req = new CreateWorldRequest { mode = mode };
return _client.Http.Post<WorldInfo>("/api/v1/worlds", req);
}
}
}
4 changes: 4 additions & 0 deletions Runtime/AsobiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AsobiClient : IDisposable
public AsobiStorage Storage { get; }
public AsobiIAP IAP { get; }
public AsobiVotes Votes { get; }
public AsobiWorlds Worlds { get; }
public AsobiDirectMessages DirectMessages { get; }
public AsobiRealtime Realtime { get; }

internal HttpClient Http { get; }
Expand Down Expand Up @@ -59,6 +61,8 @@ public AsobiClient(AsobiConfig config)
Storage = new AsobiStorage(this);
IAP = new AsobiIAP(this);
Votes = new AsobiVotes(this);
Worlds = new AsobiWorlds(this);
DirectMessages = new AsobiDirectMessages(this);
Realtime = new AsobiRealtime(this);
}

Expand Down
35 changes: 35 additions & 0 deletions Runtime/Models/DirectMessageModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace Asobi
{
[Serializable]
public class DirectMessage
{
public string id;
public string sender_id;
public string recipient_id;
public string content;
public long sent_at;
}

[Serializable]
public class DirectMessageListResponse
{
public DirectMessage[] messages;
public string channel_id;
}

[Serializable]
public class SendDmRequest
{
public string recipient_id;
public string content;
}

[Serializable]
public class DmSendResponse
{
public bool success;
public string channel_id;
}
}
7 changes: 7 additions & 0 deletions Runtime/Models/EconomyModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ public class ConsumeRequest
public string item_id;
public int quantity;
}

[Serializable]
public class ConsumeResponse
{
public bool success;
public int remaining_quantity;
}
}
2 changes: 2 additions & 0 deletions Runtime/Models/MatchModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class MatchListResponse
public class MatchmakerRequest
{
public string mode;
public string properties;
public string[] party;
}

[Serializable]
Expand Down
28 changes: 28 additions & 0 deletions Runtime/Models/RealtimeModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ internal class WsMatchmakerPayload
public string mode;
}

[Serializable]
internal class WsMatchmakerAddPayload
{
public string mode;
public string properties;
public string[] party;
}

[Serializable]
internal class WsMatchmakerRemovePayload
{
Expand All @@ -59,6 +67,26 @@ internal class WsPresencePayload
public string status;
}

[Serializable]
internal class WsWorldIdPayload
{
public string world_id;
}

[Serializable]
internal class WsWorldListPayload
{
public string mode;
public bool has_capacity;
}

[Serializable]
internal class WsDmSendPayload
{
public string recipient_id;
public string content;
}

[Serializable]
public class WsConnectedPayload
{
Expand Down
Loading