57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package rudder
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
|
)
|
|
|
|
type LeaderboardsService struct {
|
|
transport *transport
|
|
}
|
|
|
|
type ListLeaderboardsParameters struct {
|
|
Limit int
|
|
Cursor *string
|
|
}
|
|
|
|
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, nil
|
|
}
|
|
|
|
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)
|
|
}
|