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:
+34
-20
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
||||
)
|
||||
@@ -12,31 +13,44 @@ type LeaderboardsService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) ListEntries(ctx context.Context, slug string) ([]models.RankEntry, error) {
|
||||
var response models.ListLeaderboardEntriesResponse
|
||||
type ListLeaderboardsParameters struct {
|
||||
Limit int
|
||||
Cursor *string
|
||||
}
|
||||
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, nil, &response); err != nil {
|
||||
func (s *LeaderboardsService) List(ctx context.Context, parameters ListLeaderboardsParameters) (*models.ListLeaderboardsResponse, 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 models.ListLeaderboardsResponse
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/leaderboards", query, nil, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Entries, nil
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) DeleteEntry(ctx context.Context, slug string, entryID string) error {
|
||||
return s.transport.do(ctx, http.MethodDelete, "/leaderboards/"+url.PathEscape(slug)+"/entries/"+url.PathEscape(entryID), nil, nil, nil)
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) UpdateEntry(ctx context.Context, slug string, entry *models.RankEntry) error {
|
||||
body := models.UpdateLeaderboardEntryRequest{
|
||||
Score: entry.Score,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodPatch, "/leaderboards/"+url.PathEscape(slug)+"/entries/"+url.PathEscape(entry.PlayerID), nil, body, nil)
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) SubmitEntry(ctx context.Context, slug string, entry *models.RankEntry) error {
|
||||
body := models.SubmitLeaderboardEntryRequest{
|
||||
PlayerID: entry.PlayerID,
|
||||
Score: entry.Score,
|
||||
func (s *LeaderboardsService) Submit(ctx context.Context, slug string, items []models.BatchLeaderboardEntry) 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 []models.BatchLeaderboardEntry) 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user