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,70 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-go-sdk/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) (*models.ListLeaderboardEntriesResponse, 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.ListLeaderboardEntriesResponse
|
||||
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) (*models.RankEntry, error) {
|
||||
var response models.RankEntry
|
||||
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) ([]models.RankEntry, 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 []models.BatchLeaderboardEntry) error {
|
||||
return h.leaderboards.Submit(ctx, h.slug, items)
|
||||
}
|
||||
|
||||
func (h *LeaderboardHandle) Update(ctx context.Context, items []models.BatchLeaderboardEntry) 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)
|
||||
}
|
||||
Reference in New Issue
Block a user