2026-08-12 14:04:30 +03:00
|
|
|
package rudder
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type LeaderboardsService struct {
|
|
|
|
|
transport *transport
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-26 13:53:27 +03:00
|
|
|
func (s *LeaderboardsService) ListEntries(ctx context.Context, slug string) ([]models.RankEntry, error) {
|
|
|
|
|
var response models.ListLeaderboardEntriesResponse
|
|
|
|
|
|
|
|
|
|
if err := s.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, nil, &response); err != nil {
|
2026-08-12 14:04:30 +03:00
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-08-26 13:53:27 +03:00
|
|
|
|
2026-08-12 14:04:30 +03:00
|
|
|
return response.Entries, nil
|
|
|
|
|
}
|
2026-08-26 13:53:27 +03:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
return s.transport.do(ctx, http.MethodPost, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, body, nil)
|
|
|
|
|
}
|