v0.5.0: batch-first API, player/leaderboard handles, unified naming, Storage is global project storage, catalog list methods
CI / build (push) Successful in 49s
CI / build (push) Successful in 49s
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
||||
)
|
||||
|
||||
type PlayerHandle struct {
|
||||
playerID string
|
||||
transport *transport
|
||||
players *PlayersService
|
||||
wallet *WalletService
|
||||
inventory *InventoryService
|
||||
quests *QuestsService
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Wallet() *PlayerWalletHandle {
|
||||
return &PlayerWalletHandle{playerID: h.playerID, wallet: h.wallet}
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Inventory() *PlayerInventoryHandle {
|
||||
return &PlayerInventoryHandle{playerID: h.playerID, inventory: h.inventory}
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Storage() *PlayerStorageHandle {
|
||||
return &PlayerStorageHandle{playerID: h.playerID, transport: h.transport}
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Quests() *PlayerQuestsHandle {
|
||||
return &PlayerQuestsHandle{playerID: h.playerID, transport: h.transport, quests: h.quests}
|
||||
}
|
||||
|
||||
type UpdatePlayerParameters struct {
|
||||
IdempotencyKey string
|
||||
Nickname string
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Update(ctx context.Context, parameters UpdatePlayerParameters) (*models.AdminPlayer, error) {
|
||||
players, err := h.players.Update(ctx, UpdatePlayersParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []models.BatchUpdatePlayersItem{{
|
||||
PlayerID: h.playerID,
|
||||
Nickname: parameters.Nickname,
|
||||
Data: parameters.Data,
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &players[0], nil
|
||||
}
|
||||
|
||||
type BanPlayerParameters struct {
|
||||
IdempotencyKey string
|
||||
Reason string
|
||||
BannedUntil string
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Ban(ctx context.Context, parameters BanPlayerParameters) (*models.AdminPlayer, error) {
|
||||
players, err := h.players.Ban(ctx, BanPlayersParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []models.BatchBanPlayersItem{{
|
||||
PlayerID: h.playerID,
|
||||
Reason: parameters.Reason,
|
||||
BannedUntil: parameters.BannedUntil,
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &players[0], nil
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Unban(ctx context.Context, idempotencyKey string) (*models.AdminPlayer, error) {
|
||||
players, err := h.players.Unban(ctx, UnbanPlayersParameters{
|
||||
IdempotencyKey: idempotencyKey,
|
||||
Items: []models.BatchPlayerItem{{PlayerID: h.playerID}},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &players[0], nil
|
||||
}
|
||||
|
||||
func (h *PlayerHandle) Delete(ctx context.Context, idempotencyKey string) error {
|
||||
return h.players.Delete(ctx, DeletePlayersParameters{
|
||||
IdempotencyKey: idempotencyKey,
|
||||
Items: []models.BatchPlayerItem{{PlayerID: h.playerID}},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user