PlayPortalLeaderboardClient

This class is responsible for making requests to the playPORTAL leaderboard API.
public final class PlayPortalLeaderboardClient

While playPORTAL buckets allow your app to store private data for a single user, or share data between multiple users, leaderboards allow you to create and share scores between all users of your app. Leaderboard scores will be returned sorted, allowing you to create high score leaderboards visible to all users of your app. You can also create leaderboard entries with a "category" tag, allowing you to create multiple distinct leaderboards for your app.

You will need to enable the "Leaderboard" scope for your app in the developer dashboard before using the leaderboard API.

Properties

public static let shared: PlayPortalLeaderboardClient

Singleton instance of PlayPortalLeaderboardClient. You will access all the available PlayPortalLeaderboardClient methods through this instance.

Methods

getLeaderboard

public func getLeaderboardEntries(_ page: Int? = nil, _ limit: Int? = nil, forCategories categories: [String], _ completion: @escaping (_ error: Error?, _ leaderboardEntries: [PlayPortalLeaderboardEntry]?) -> Void) -> Void

Get all leaderboard entries for your app or filter out leaderboard entries by supplying one or more category tags. Supports pagination through the page and limit parameters.

Parameter

Type

Description

page

Int?

At what page to return leaderboard entries, where page length is determined by limit.

limit

Int?

The maximum number of leaderboard entries to return.

forCategories

[String]

Filter leaderboard entries by specifying what entries to return based on their category tags. An empty array will return all entries.

completion

(Error?, [PlayPortalLeaderboardEntry]?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

leaderboardEntries

[PlayPortalLeaderboardEntry]?

The leaderboard entries returned for a successful request.

updateLeaderboard

public func updateLeaderboard(_ score: Double, forCategories categories: [String], _ completion: ((_ error: Error?, _ leaderboardEntry: PlayPortalLeaderboardEntry?) -> Void)?) -> Void

Add a leaderboard entry. Entries are simply represented by a score (Double) and can be created with zero or more category tags. If a leaderboard entry already exists with the same categories, an upsert will be performed, rather than creating a new entry.

Parameter

Type

Description

score

Double

The score being added.

forCategories

[String]

List of categories to tag the leaderboard with.

completion

((Error?, PlayPortalLeaderboardEntry?) -> Void)?

The closure invoked after the request finishes.

error

Error?

The error returned for an unsuccessful request.

leaderboardEntry

PlayPortalLeaderboardEntry?

The newly created leaderboard entry returned for a successful request.