Implement Godot API client with REST social helpers and WebSocket gateway client (task 264d84d07f28)

This commit is contained in:
2026-09-15 19:25:27 +00:00
parent 21397b710a
commit 246b7ac996
4 changed files with 655 additions and 0 deletions
+199
View File
@@ -82,6 +82,9 @@ var base_url: String:
## Request timeout in seconds. 0 disables the timeout.
var timeout_seconds: float = 10.0
## Real-time WebSocket gateway client instance
var ws: WsGatewayClient = null
func _ready() -> void:
# Environment variable override (e.g. for headless smoke tests against a
@@ -96,6 +99,24 @@ func _ready() -> void:
"http://127.0.0.1:8000"
)).rstrip("/")
ws = WsGatewayClient.new()
ws.name = "WsGatewayClient"
add_child(ws)
## Connect to the WebSocket gateway using the current base_url and stored token.
func connect_ws_gateway(token: String = "") -> Error:
if ws == null:
return ERR_UNCONFIGURED
var tok := token if token != "" else _access_token
return ws.connect_gateway(_base_url, tok)
## Disconnect from the WebSocket gateway.
func disconnect_ws_gateway() -> void:
if ws != null:
ws.disconnect_gateway()
# ---------------------------------------------------------------------------
# Core request primitive
@@ -255,6 +276,184 @@ func save_avatar_loadout(loadout: Dictionary) -> Dictionary:
return await request(HTTPClient.METHOD_PUT, "/api/avatar/loadout", body, "application/json", true)
# ---------------------------------------------------------------------------
# Social Features: Friends, Follow & Block
# ---------------------------------------------------------------------------
## Send a friend request to target user_id.
func send_friend_request(user_id: int) -> Dictionary:
return await SocialApiClient.send_friend_request(self, user_id)
## Get pending incoming friend requests.
func get_friend_requests() -> Dictionary:
return await SocialApiClient.get_friend_requests(self)
## Accept an incoming friend request.
func accept_friend_request(request_id: int) -> Dictionary:
return await SocialApiClient.accept_friend_request(self, request_id)
## Decline an incoming friend request.
func decline_friend_request(request_id: int) -> Dictionary:
return await SocialApiClient.decline_friend_request(self, request_id)
## Remove an existing friend.
func unfriend(user_id: int) -> Dictionary:
return await SocialApiClient.unfriend(self, user_id)
## Get list of mutual friends.
func get_friends() -> Dictionary:
return await SocialApiClient.get_friends(self)
## Follow a user.
func follow_user(user_id: int) -> Dictionary:
return await SocialApiClient.follow_user(self, user_id)
## Unfollow a user.
func unfollow_user(user_id: int) -> Dictionary:
return await SocialApiClient.unfollow_user(self, user_id)
## Get list of users followed by current user.
func get_following() -> Dictionary:
return await SocialApiClient.get_following(self)
## Block a user.
func block_user(user_id: int) -> Dictionary:
return await SocialApiClient.block_user(self, user_id)
## Unblock a user.
func unblock_user(user_id: int) -> Dictionary:
return await SocialApiClient.unblock_user(self, user_id)
## Get list of blocked users.
func get_blocked() -> Dictionary:
return await SocialApiClient.get_blocked(self)
# ---------------------------------------------------------------------------
# Social Features: Presence
# ---------------------------------------------------------------------------
## Send presence heartbeat with optional custom status.
func send_presence_heartbeat(custom_status: String = "") -> Dictionary:
return await SocialApiClient.send_presence_heartbeat(self, custom_status)
## Get presence status of mutual friends.
func get_friends_presence() -> Dictionary:
return await SocialApiClient.get_friends_presence(self)
## Get presence status of a specific user.
func get_user_presence(user_id: int) -> Dictionary:
return await SocialApiClient.get_user_presence(self, user_id)
# ---------------------------------------------------------------------------
# Social Features: Profiles
# ---------------------------------------------------------------------------
## Get current user's own profile.
func get_my_profile() -> Dictionary:
return await SocialApiClient.get_my_profile(self)
## Update current user's bio, avatar asset, or privacy settings.
func update_my_profile(bio: Variant = null, avatar_asset_id: Variant = null, privacy: Variant = null) -> Dictionary:
return await SocialApiClient.update_my_profile(self, bio, avatar_asset_id, privacy)
## Get current user's favorited world IDs.
func get_my_favorites() -> Dictionary:
return await SocialApiClient.get_my_favorites(self)
## Replace current user's favorited world IDs.
func replace_my_favorites(world_ids: Array) -> Dictionary:
return await SocialApiClient.replace_my_favorites(self, world_ids)
## Get public profile of another user.
func get_public_profile(user_id: int) -> Dictionary:
return await SocialApiClient.get_public_profile(self, user_id)
# ---------------------------------------------------------------------------
# Social Features: Groups
# ---------------------------------------------------------------------------
## Create a new group.
func create_group(name: String, description: String = "") -> Dictionary:
return await SocialApiClient.create_group(self, name, description)
## List groups.
func list_groups(page: int = 1, page_size: int = 50, mine: bool = false) -> Dictionary:
return await SocialApiClient.list_groups(self, page, page_size, mine)
## Get group details and member list.
func get_group(group_id: int) -> Dictionary:
return await SocialApiClient.get_group(self, group_id)
## Update group name or description.
func update_group(group_id: int, name: Variant = null, description: Variant = null) -> Dictionary:
return await SocialApiClient.update_group(self, group_id, name, description)
## Delete a group (owner only).
func delete_group(group_id: int) -> Dictionary:
return await SocialApiClient.delete_group(self, group_id)
## Join a group.
func join_group(group_id: int) -> Dictionary:
return await SocialApiClient.join_group(self, group_id)
## Leave a group.
func leave_group(group_id: int) -> Dictionary:
return await SocialApiClient.leave_group(self, group_id)
## Set a member's role in a group.
func set_group_member_role(group_id: int, user_id: int, role: String) -> Dictionary:
return await SocialApiClient.set_group_member_role(self, group_id, user_id, role)
## Transfer ownership of a group.
func transfer_group_ownership(group_id: int, new_owner_id: int) -> Dictionary:
return await SocialApiClient.transfer_group_ownership(self, group_id, new_owner_id)
# ---------------------------------------------------------------------------
# Social Features: Chat & Moderation
# ---------------------------------------------------------------------------
## List DM conversations for the authenticated user.
func get_dm_conversations() -> Dictionary:
return await SocialApiClient.get_dm_conversations(self)
## Start or get existing DM conversation with target user.
func start_dm_conversation(target_user_id: int) -> Dictionary:
return await SocialApiClient.start_dm_conversation(self, target_user_id)
## Get DM messages for a conversation.
func get_dm_messages(conversation_id: int, before_id: int = 0, limit: int = 50) -> Dictionary:
return await SocialApiClient.get_dm_messages(self, conversation_id, before_id, limit)
## Send a DM message to a conversation.
func send_dm_message(conversation_id: int, content: String) -> Dictionary:
return await SocialApiClient.send_dm_message(self, conversation_id, content)
## Get messages in world chat.
func get_world_chat_messages(world_id: int, before_id: int = 0, limit: int = 50) -> Dictionary:
return await SocialApiClient.get_world_chat_messages(self, world_id, before_id, limit)
## Send a message to world chat.
func send_world_chat_message(world_id: int, content: String) -> Dictionary:
return await SocialApiClient.send_world_chat_message(self, world_id, content)
## Get messages in room chat.
func get_room_chat_messages(room_id: String, before_id: int = 0, limit: int = 50) -> Dictionary:
return await SocialApiClient.get_room_chat_messages(self, room_id, before_id, limit)
## Send a message to room chat.
func send_room_chat_message(room_id: String, content: String) -> Dictionary:
return await SocialApiClient.send_room_chat_message(self, room_id, content)
## Report a message to the moderation queue.
func report_message(message_id: int, conversation_type: String, reason: String, context_text: String = "") -> Dictionary:
return await SocialApiClient.report_message(self, message_id, conversation_type, reason, context_text)
# ---------------------------------------------------------------------------
# Internals
# ---------------------------------------------------------------------------