feat: resource rows batch operations, drop removed domains, regenerated models
This commit is contained in:
@@ -16,11 +16,10 @@ type Config struct {
|
||||
|
||||
type Client struct {
|
||||
Players *PlayersService
|
||||
Leaderboards *LeaderboardsService
|
||||
Wallet *WalletService
|
||||
Inventory *InventoryService
|
||||
Quests *QuestsService
|
||||
Storage *StorageService
|
||||
Resources *ResourcesService
|
||||
Modules *ModulesService
|
||||
|
||||
transport *transport
|
||||
}
|
||||
@@ -48,11 +47,10 @@ func New(config Config) (*Client, error) {
|
||||
|
||||
return &Client{
|
||||
Players: &PlayersService{transport: transport},
|
||||
Leaderboards: &LeaderboardsService{transport: transport},
|
||||
Wallet: &WalletService{transport: transport},
|
||||
Inventory: &InventoryService{transport: transport},
|
||||
Quests: &QuestsService{transport: transport},
|
||||
Storage: &StorageService{transport: transport},
|
||||
Resources: &ResourcesService{transport: transport},
|
||||
Modules: &ModulesService{transport: transport},
|
||||
|
||||
transport: transport,
|
||||
}, nil
|
||||
@@ -64,15 +62,5 @@ func (c *Client) Player(playerID string) *PlayerHandle {
|
||||
transport: c.transport,
|
||||
players: c.Players,
|
||||
wallet: c.Wallet,
|
||||
inventory: c.Inventory,
|
||||
quests: c.Quests,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Leaderboard(slug string) *LeaderboardHandle {
|
||||
return &LeaderboardHandle{
|
||||
slug: slug,
|
||||
transport: c.transport,
|
||||
leaderboards: c.Leaderboards,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/v2/models"
|
||||
)
|
||||
|
||||
type InventoryService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
type AdjustInventoryParameters struct {
|
||||
IdempotencyKey string
|
||||
Items []InventoryAdjustment
|
||||
}
|
||||
|
||||
func (s *InventoryService) Adjust(ctx context.Context, parameters AdjustInventoryParameters) ([]InventoryItem, error) {
|
||||
body := models.BatchAdjustPlayerInventoryItemsRequest{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: parameters.Items,
|
||||
}
|
||||
|
||||
var response models.BatchAdjustPlayerInventoryItemsResponse
|
||||
if err := s.transport.do(ctx, http.MethodPost, "/players/inventory/adjust", nil, body, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response.Items, nil
|
||||
}
|
||||
|
||||
type ListInventoryParameters struct {
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
func (s *InventoryService) List(ctx context.Context, playerID string, parameters ListInventoryParameters) (*InventoryList, error) {
|
||||
query := url.Values{}
|
||||
if parameters.Limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(parameters.Limit))
|
||||
}
|
||||
if parameters.Cursor != nil {
|
||||
query.Set("cursor", *parameters.Cursor)
|
||||
}
|
||||
|
||||
var response InventoryList
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/players/"+url.PathEscape(playerID)+"/inventory", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/v2/models"
|
||||
)
|
||||
|
||||
type LeaderboardHandle struct {
|
||||
slug string
|
||||
transport *transport
|
||||
leaderboards *LeaderboardsService
|
||||
}
|
||||
|
||||
type ListLeaderboardEntriesParameters struct {
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) List(ctx context.Context, parameters ListLeaderboardEntriesParameters) (*RankList, error) {
|
||||
query := url.Values{}
|
||||
if parameters.Limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(parameters.Limit))
|
||||
}
|
||||
if parameters.Cursor != nil {
|
||||
query.Set("cursor", *parameters.Cursor)
|
||||
}
|
||||
|
||||
var response RankList
|
||||
if err := h.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(h.slug)+"/entries", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) Get(ctx context.Context, playerID string) (*Rank, error) {
|
||||
var response Rank
|
||||
if err := h.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(h.slug)+"/entries/"+url.PathEscape(playerID), nil, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) GetAround(ctx context.Context, playerID string, limit int) ([]Rank, error) {
|
||||
query := url.Values{}
|
||||
if limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(limit))
|
||||
}
|
||||
|
||||
var response models.GetLeaderboardEntryAroundResponse
|
||||
if err := h.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(h.slug)+"/entries/"+url.PathEscape(playerID)+"/around", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response.Entries, nil
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) Submit(ctx context.Context, items []LeaderboardScore) error {
|
||||
return h.leaderboards.Submit(ctx, h.slug, items)
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) Update(ctx context.Context, items []LeaderboardScore) error {
|
||||
return h.leaderboards.Update(ctx, h.slug, items)
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) Delete(ctx context.Context, playerIDs []string) error {
|
||||
return h.leaderboards.Delete(ctx, h.slug, playerIDs)
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/v2/models"
|
||||
)
|
||||
|
||||
type LeaderboardsService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
type ListLeaderboardsParameters struct {
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) List(ctx context.Context, parameters ListLeaderboardsParameters) (*LeaderboardList, error) {
|
||||
query := url.Values{}
|
||||
if parameters.Limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(parameters.Limit))
|
||||
}
|
||||
if parameters.Cursor != nil {
|
||||
query.Set("cursor", *parameters.Cursor)
|
||||
}
|
||||
|
||||
var response LeaderboardList
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/leaderboards", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) Submit(ctx context.Context, slug string, items []LeaderboardScore) error {
|
||||
body := models.BatchSubmitLeaderboardEntriesRequest{
|
||||
Items: items,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodPost, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, body, nil)
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) Update(ctx context.Context, slug string, items []LeaderboardScore) error {
|
||||
body := models.BatchUpdateLeaderboardEntriesRequest{
|
||||
Items: items,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodPatch, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, body, nil)
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) Delete(ctx context.Context, slug string, playerIDs []string) error {
|
||||
body := models.BatchDeleteLeaderboardEntriesRequest{
|
||||
PlayerIds: playerIDs,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodDelete, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, body, nil)
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type AdminListQuestsResponse struct {
|
||||
Items []QuestDefinition `json:"items,omitempty"`
|
||||
NextCursor string `json:"nextCursor,omitempty"`
|
||||
}
|
||||
@@ -4,7 +4,6 @@ package models
|
||||
|
||||
type AdminPlayerDetails struct {
|
||||
Identities []PlayerIdentity `json:"identities,omitempty"`
|
||||
Inventory []InventoryItem `json:"inventory,omitempty"`
|
||||
Player AdminPlayer `json:"player,omitempty"`
|
||||
Storages []PlayerStorage `json:"storages,omitempty"`
|
||||
WalletTransactions []WalletAudit `json:"walletTransactions,omitempty"`
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type AdminPlayerQuest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Objectives []AdminPlayerQuestObjective `json:"objectives,omitempty"`
|
||||
QuestSlug string `json:"questSlug,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type AdminPlayerQuestObjective struct {
|
||||
Current int64 `json:"current,omitempty"`
|
||||
ObjectiveID string `json:"objectiveId,omitempty"`
|
||||
Target int64 `json:"target,omitempty"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchAdjustPlayerInventoryItemsItem struct {
|
||||
Amount int64 `json:"amount,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchAdjustPlayerInventoryItemsRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Items []BatchAdjustPlayerInventoryItemsItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchAdjustPlayerInventoryItemsResponse struct {
|
||||
Items []InventoryItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type BatchCreateResourceRowItem struct {
|
||||
Data json.RawMessage `json:"data,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchCreateResourceRowsRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Items []BatchCreateResourceRowItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchDeleteLeaderboardEntriesRequest struct {
|
||||
PlayerIds []string `json:"playerIds,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchDeleteResourceRowItem struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchDeleteResourceRowsRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Items []BatchDeleteResourceRowItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchLeaderboardEntry struct {
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
Score float64 `json:"score,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchPlayerQuestsItem struct {
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
QuestSlug string `json:"questSlug,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchPlayerQuestsRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Items []BatchPlayerQuestsItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchSubmitLeaderboardEntriesRequest struct {
|
||||
Items []BatchLeaderboardEntry `json:"items,omitempty"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchUpdateLeaderboardEntriesRequest struct {
|
||||
Items []BatchLeaderboardEntry `json:"items,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type BatchUpdateResourceRowItem struct {
|
||||
Data json.RawMessage `json:"data,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
Version int64 `json:"version,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type BatchUpdateResourceRowsRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Items []BatchUpdateResourceRowItem `json:"items,omitempty"`
|
||||
}
|
||||
@@ -3,13 +3,6 @@
|
||||
package models
|
||||
|
||||
const (
|
||||
ErrorCodeEarlyCompletion = "early_completion"
|
||||
ErrorCodeForbidden = "forbidden"
|
||||
ErrorCodeLevelNotReached = "level_not_reached"
|
||||
ErrorCodeNodeNotActive = "node_not_active"
|
||||
ErrorCodeObjectivesIncomplete = "objectives_incomplete"
|
||||
ErrorCodeRunExpired = "run_expired"
|
||||
ErrorCodeRunNotActive = "run_not_active"
|
||||
ErrorCodeScenarioNotActive = "scenario_not_active"
|
||||
ErrorCodeUnknownRun = "unknown_run"
|
||||
ErrorCodeRowReferenced = "row_referenced"
|
||||
)
|
||||
|
||||
@@ -6,6 +6,8 @@ type ErrorResponse struct {
|
||||
Code string `json:"code,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Index int `json:"index,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
RequestID string `json:"requestId,omitempty"`
|
||||
Usages []ResourceRowUsage `json:"usages,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type GetLeaderboardEntryAroundResponse struct {
|
||||
Entries []RankEntry `json:"entries,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type GetPlayerInventoryResponse struct {
|
||||
Items []InventoryItem `json:"items,omitempty"`
|
||||
NextCursor string `json:"nextCursor,omitempty"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type InventoryItem struct {
|
||||
Amount int64 `json:"amount,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type LeaderboardDefinition struct {
|
||||
MaxEntries int64 `json:"maxEntries,omitempty"`
|
||||
Metric string `json:"metric,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ResetPeriod string `json:"resetPeriod,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
SortingOrder string `json:"sortingOrder,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type ListLeaderboardEntriesResponse struct {
|
||||
Entries []RankEntry `json:"entries,omitempty"`
|
||||
NextCursor string `json:"nextCursor,omitempty"`
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type ListLeaderboardsResponse struct {
|
||||
Items []LeaderboardDefinition `json:"items,omitempty"`
|
||||
NextCursor string `json:"nextCursor,omitempty"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type ListPlayerQuestsResponse struct {
|
||||
Quests []AdminPlayerQuest `json:"quests,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type ListResourceRowsResponse struct {
|
||||
Items []ResourceRow `json:"items,omitempty"`
|
||||
Total int `json:"total,omitempty"`
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type QuestDefinition struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
NextQuestID string `json:"nextQuestId,omitempty"`
|
||||
Objectives []QuestObjective `json:"objectives,omitempty"`
|
||||
Rewards []QuestRewardDefinition `json:"rewards,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type QuestObjective struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Metric string `json:"metric,omitempty"`
|
||||
Target int64 `json:"target,omitempty"`
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type QuestRewardDefinition struct {
|
||||
Amount int64 `json:"amount,omitempty"`
|
||||
Currency string `json:"currency,omitempty"`
|
||||
ItemID string `json:"itemId,omitempty"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type RankEntry struct {
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
PlayerName string `json:"playerName,omitempty"`
|
||||
Rank int64 `json:"rank,omitempty"`
|
||||
Score float64 `json:"score,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type ResourceRow struct {
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Data json.RawMessage `json:"data,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
PlayerID string `json:"playerId,omitempty"`
|
||||
Rank int64 `json:"rank,omitempty"`
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
Version int64 `json:"version,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
type ResourceRowUsage struct {
|
||||
DefinitionSlug string `json:"definitionSlug,omitempty"`
|
||||
Field string `json:"field,omitempty"`
|
||||
ModuleSlug string `json:"moduleSlug,omitempty"`
|
||||
RowID string `json:"rowId,omitempty"`
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ModulesService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
type CallParameters struct {
|
||||
Module string
|
||||
Fn string
|
||||
Args any
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
type CallResult struct {
|
||||
Result any `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Log []any `json:"log"`
|
||||
Console []string `json:"console"`
|
||||
}
|
||||
|
||||
func (s *ModulesService) Call(ctx context.Context, parameters CallParameters) (*CallResult, error) {
|
||||
var result CallResult
|
||||
path := fmt.Sprintf("/modules/%s/%s", parameters.Module, parameters.Fn)
|
||||
body := map[string]any{"args": parameters.Args, "dryRun": parameters.DryRun}
|
||||
if err := s.transport.do(ctx, http.MethodPost, path, nil, body, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@@ -10,26 +10,16 @@ type PlayerHandle struct {
|
||||
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
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import "context"
|
||||
|
||||
type PlayerInventoryHandle struct {
|
||||
playerID string
|
||||
inventory *InventoryService
|
||||
}
|
||||
|
||||
type AdjustPlayerInventoryParameters struct {
|
||||
IdempotencyKey string
|
||||
Slug string
|
||||
Amount int64
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (h *PlayerInventoryHandle) Adjust(ctx context.Context, parameters AdjustPlayerInventoryParameters) (*InventoryItem, error) {
|
||||
items, err := h.inventory.Adjust(ctx, AdjustInventoryParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []InventoryAdjustment{{
|
||||
PlayerID: h.playerID,
|
||||
Slug: parameters.Slug,
|
||||
Amount: parameters.Amount,
|
||||
Reason: parameters.Reason,
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &items[0], nil
|
||||
}
|
||||
|
||||
func (h *PlayerInventoryHandle) List(ctx context.Context, parameters ListInventoryParameters) (*InventoryList, error) {
|
||||
return h.inventory.List(ctx, h.playerID, parameters)
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/v2/models"
|
||||
)
|
||||
|
||||
type PlayerQuestsHandle struct {
|
||||
playerID string
|
||||
transport *transport
|
||||
quests *QuestsService
|
||||
}
|
||||
|
||||
func (h *PlayerQuestsHandle) List(ctx context.Context) ([]PlayerQuest, error) {
|
||||
var response models.ListPlayerQuestsResponse
|
||||
if err := h.transport.do(ctx, http.MethodGet, "/players/"+url.PathEscape(h.playerID)+"/quests", nil, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response.Quests, nil
|
||||
}
|
||||
|
||||
type PlayerQuestParameters struct {
|
||||
IdempotencyKey string
|
||||
QuestSlug string
|
||||
}
|
||||
|
||||
func (h *PlayerQuestsHandle) Reset(ctx context.Context, parameters PlayerQuestParameters) error {
|
||||
return h.quests.Reset(ctx, PlayerQuestsParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []PlayerQuestRef{{PlayerID: h.playerID, QuestSlug: parameters.QuestSlug}},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *PlayerQuestsHandle) ForceComplete(ctx context.Context, parameters PlayerQuestParameters) error {
|
||||
return h.quests.ForceComplete(ctx, PlayerQuestsParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []PlayerQuestRef{{PlayerID: h.playerID, QuestSlug: parameters.QuestSlug}},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *PlayerQuestsHandle) ForceClaim(ctx context.Context, parameters PlayerQuestParameters) error {
|
||||
return h.quests.ForceClaim(ctx, PlayerQuestsParameters{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: []PlayerQuestRef{{PlayerID: h.playerID, QuestSlug: parameters.QuestSlug}},
|
||||
})
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/v2/models"
|
||||
)
|
||||
|
||||
type QuestsService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
type ListQuestsParameters struct {
|
||||
Status *string
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
func (s *QuestsService) List(ctx context.Context, parameters ListQuestsParameters) (*QuestList, error) {
|
||||
query := url.Values{}
|
||||
if parameters.Status != nil {
|
||||
query.Set("status", *parameters.Status)
|
||||
}
|
||||
if parameters.Limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(parameters.Limit))
|
||||
}
|
||||
if parameters.Cursor != nil {
|
||||
query.Set("cursor", *parameters.Cursor)
|
||||
}
|
||||
|
||||
var response QuestList
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/quests", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
type PlayerQuestsParameters struct {
|
||||
IdempotencyKey string
|
||||
Items []PlayerQuestRef
|
||||
}
|
||||
|
||||
func (s *QuestsService) Reset(ctx context.Context, parameters PlayerQuestsParameters) error {
|
||||
return s.postPlayerQuests(ctx, "/players/quests/reset", parameters)
|
||||
}
|
||||
|
||||
func (s *QuestsService) ForceComplete(ctx context.Context, parameters PlayerQuestsParameters) error {
|
||||
return s.postPlayerQuests(ctx, "/players/quests/force-complete", parameters)
|
||||
}
|
||||
|
||||
func (s *QuestsService) ForceClaim(ctx context.Context, parameters PlayerQuestsParameters) error {
|
||||
return s.postPlayerQuests(ctx, "/players/quests/force-claim", parameters)
|
||||
}
|
||||
|
||||
func (s *QuestsService) postPlayerQuests(ctx context.Context, path string, parameters PlayerQuestsParameters) error {
|
||||
body := models.BatchPlayerQuestsRequest{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: parameters.Items,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodPost, path, nil, body, nil)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ResourcesService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
type ResourceBatchItem struct {
|
||||
PlayerID string `json:"playerId"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Data map[string]any `json:"data,omitempty"`
|
||||
Version int64 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceRowsPage struct {
|
||||
Items []any `json:"items"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (s *ResourcesService) List(ctx context.Context, slug string) (*ResourceRowsPage, error) {
|
||||
var page ResourceRowsPage
|
||||
path := fmt.Sprintf("/resources/%s/rows", slug)
|
||||
if err := s.transport.do(ctx, http.MethodGet, path, nil, nil, &page); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &page, nil
|
||||
}
|
||||
|
||||
func (s *ResourcesService) Create(ctx context.Context, slug string, items []ResourceBatchItem) (*ResourceRowsPage, error) {
|
||||
var page ResourceRowsPage
|
||||
path := fmt.Sprintf("/resources/%s/rows", slug)
|
||||
if err := s.transport.do(ctx, http.MethodPost, path, nil, map[string]any{"items": items}, &page); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &page, nil
|
||||
}
|
||||
|
||||
func (s *ResourcesService) Update(ctx context.Context, slug string, items []ResourceBatchItem) (*ResourceRowsPage, error) {
|
||||
var page ResourceRowsPage
|
||||
path := fmt.Sprintf("/resources/%s/rows", slug)
|
||||
if err := s.transport.do(ctx, http.MethodPatch, path, nil, map[string]any{"items": items}, &page); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &page, nil
|
||||
}
|
||||
|
||||
func (s *ResourcesService) Delete(ctx context.Context, slug string, items []ResourceBatchItem) error {
|
||||
path := fmt.Sprintf("/resources/%s/rows", slug)
|
||||
return s.transport.do(ctx, http.MethodDelete, path, nil, map[string]any{"items": items}, nil)
|
||||
}
|
||||
@@ -17,25 +17,7 @@ type WalletTransaction = models.WalletAudit
|
||||
type WalletHistory = models.GetWalletHistoryResponse
|
||||
type WalletAdjustment = models.BatchAdjustPlayerWalletsItem
|
||||
|
||||
type InventoryItem = models.InventoryItem
|
||||
type InventoryList = models.GetPlayerInventoryResponse
|
||||
type InventoryAdjustment = models.BatchAdjustPlayerInventoryItemsItem
|
||||
|
||||
type PlayerStorage = models.PlayerStorage
|
||||
type ProjectStorage = models.ProjectStorageItem
|
||||
type ProjectStorageList = models.GetProjectStorageResponse
|
||||
type ProjectStorageInput = models.AdminProjectStorageItem
|
||||
|
||||
type PlayerQuest = models.AdminPlayerQuest
|
||||
type PlayerQuestObjective = models.AdminPlayerQuestObjective
|
||||
type PlayerQuestRef = models.BatchPlayerQuestsItem
|
||||
type Quest = models.QuestDefinition
|
||||
type QuestObjective = models.QuestObjective
|
||||
type QuestReward = models.QuestRewardDefinition
|
||||
type QuestList = models.AdminListQuestsResponse
|
||||
|
||||
type Leaderboard = models.LeaderboardDefinition
|
||||
type LeaderboardList = models.ListLeaderboardsResponse
|
||||
type LeaderboardScore = models.BatchLeaderboardEntry
|
||||
type Rank = models.RankEntry
|
||||
type RankList = models.ListLeaderboardEntriesResponse
|
||||
|
||||
Reference in New Issue
Block a user