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) (*LeaderboardList, 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 LeaderboardList 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 []LeaderboardScore) 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 []LeaderboardScore) 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) }