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:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
||||
)
|
||||
@@ -13,23 +14,43 @@ type WalletService struct {
|
||||
}
|
||||
|
||||
type AdjustWalletParameters struct {
|
||||
CurrencyCode string
|
||||
Amount int64
|
||||
Reason string
|
||||
IdempotencyKey string
|
||||
Items []models.BatchAdjustPlayerWalletsItem
|
||||
}
|
||||
|
||||
func (s *WalletService) Adjust(ctx context.Context, playerID string, parameters AdjustWalletParameters) (*models.WalletDetails, error) {
|
||||
body := models.AdjustPlayerWalletRequest{
|
||||
PlayerID: playerID,
|
||||
CurrencyCode: parameters.CurrencyCode,
|
||||
Amount: parameters.Amount,
|
||||
Reason: parameters.Reason,
|
||||
func (s *WalletService) Adjust(ctx context.Context, parameters AdjustWalletParameters) ([]models.WalletDetails, error) {
|
||||
body := models.BatchAdjustPlayerWalletsRequest{
|
||||
IdempotencyKey: parameters.IdempotencyKey,
|
||||
Items: parameters.Items,
|
||||
}
|
||||
|
||||
var response models.WalletDetails
|
||||
if err := s.transport.do(ctx, http.MethodPost, "/players/"+url.PathEscape(playerID)+"/wallet/adjust", nil, body, &response); err != nil {
|
||||
var response models.BatchAdjustPlayerWalletsResponse
|
||||
if err := s.transport.do(ctx, http.MethodPost, "/players/wallet/adjust", nil, body, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response.Wallets, nil
|
||||
}
|
||||
|
||||
type WalletHistoryParameters struct {
|
||||
Currency *string
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
func (s *WalletService) History(ctx context.Context, playerID string, parameters WalletHistoryParameters) (*models.GetWalletHistoryResponse, error) {
|
||||
query := url.Values{}
|
||||
if parameters.Currency != nil {
|
||||
query.Set("currency", *parameters.Currency)
|
||||
}
|
||||
if parameters.Limit > 0 {
|
||||
query.Set("limit", strconv.Itoa(parameters.Limit))
|
||||
}
|
||||
if parameters.Cursor != nil {
|
||||
query.Set("cursor", *parameters.Cursor)
|
||||
}
|
||||
|
||||
var response models.GetWalletHistoryResponse
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/players/"+url.PathEscape(playerID)+"/wallet/history", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &response, nil
|
||||
|
||||
Reference in New Issue
Block a user