leaderboards: ListEntries/SubmitEntry/UpdateEntry/DeleteEntry against /entries
CI / build (push) Successful in 50s
CI / build (push) Successful in 50s
This commit is contained in:
+24
-3
@@ -12,10 +12,31 @@ type LeaderboardsService struct {
|
||||
transport *transport
|
||||
}
|
||||
|
||||
func (s *LeaderboardsService) Results(ctx context.Context, slug string) ([]models.RankEntry, error) {
|
||||
var response models.GetLeaderboardResultsResponse
|
||||
if err := s.transport.do(ctx, http.MethodGet, "/leaderboards/"+url.PathEscape(slug)+"/results", nil, nil, &response); err != nil {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Entries, 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,
|
||||
}
|
||||
return s.transport.do(ctx, http.MethodPost, "/leaderboards/"+url.PathEscape(slug)+"/entries", nil, body, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user