PlayPortalUserClient

This class is responsible for making requests to the playPORTAL user API.
public final class PlayPortalUserClient

The PlayPortalUserClient class allows your app to request the current user's profile, request the current user's friends, and search for other playPORTAL users, giving your app access to the playPORTAL social network.

You will need to enable the "Profile" and "Smart Search" scopes for your app in the developer dashboard before using the user API.

Properties

public static let shared: PlayPortalUserClient

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

Methods

getMyProfile

public func getMyProfile(completion: @escaping (_ error: Error?, _ userProfile: PlayPortalProfile?) -> Void) -> Void

Request the currently authenticated user's profile. It's unlikely that you will need to directly use this method, as the isAuthenticated method on PlayPortalAuth will pass an instance of PlayPortalProfile representing the current user.

Parameter

Type

Description

completion

(Error?, PlayPortalProfile?) -> Void

The closure that will be invoked once the request finishes.

error

Error?

The error returned for an unsuccessful request.

userProfile

PlayPortalProfile?

An instance of PlayPortalProfile representing the current user that will be returned for a successful request.

getMyFriends

public func getMyFriends(completion: @escaping (_ error: Error?, _ friendProfiles: [PlayPortalProfile]?) -> Void) -> Void

Request the current user's friends list. When running in sandbox mode, you can created friendship links between sandbox users in the developer dashboard, allowing you to create and test a social network in your app.

Parameter

Type

Description

completion

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

The closure that will be invoked once the request finishes.

error

Error?

The error returned for an unsuccessful request.

friendProfiles

[PlayPortalProfile]?

An array of PlayPortalProfiles representing the current user's friends returned for a successful request.

searchUsers

public func searchUsers(searchTerm: String, page: Int? = nil, limit: Int? = nil, completion: @escaping (_ error: Error?, _ users: [PlayPortalProfile]?) -> Void) -> Void

Search for playPORTAL users by a search term. The search term will be compared against users' handle, first name, and last name. Supports pagination through the page and limit parameters.

Parameter

Type

Description

searchTerm

String

What users will be searched by.

page

Int?

At what page to return users, where the page length is determined by limit.

limit

Int?

The maximum number of users to return.

completion

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

The closure that will be invoked once the request finishes.

error

Error?

The error returned for an unsuccessful request.

users

[PlayPortalProfile]?

An array of PlayPortalProfiles that matched the search term returned for a successful request.

getRandomUsers

public func getRandomUsers(count: Int, completion: @escaping (_ error: Error?, _ users: [PlayPortalProfile]?) -> Void) -> Void

Request a number of random users. This is useful if you want to display a number of random profiles without requiring the user to search for them.

Parameter

Type

Description

count

Int

The number of random users to return.

completion

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

The closure that will be invoked once the request finishes.

error

Error?

The error returned for an unsuccessful request.

users

[PlayPortalProfile]?

An array of PlayPortalProfiles representing the random users returned for a successful request.

createAnonymousUser

public func createAnonymousUser(clientId: String, dateOfBirth: String, deviceToken: Data? = nil, completion: @escaping (_ error: Error?, _ anonymousUser: PlayPortalProfile?) -> Void) -> Void

Create an anonymous user that can be used in place of a user created through the playPORTAL signup flow.

The lifetime of an anonymous user is essentially as long as they are logged into the app. Once an anonymous user logs out, a new anonymous user will have to be created.

Anonymous users do not have access to some functionality, such as Leaderboards and Smart Search. Making requests to those APIs, ie, via the PlayPortalLeaderboard class, will return an error.

Parameter

Type

Description

clientId

String

Client id associated with the app.

dateOfBirth

String

Date string representing the user's date of birth. This is required to create the appropriate type of account for the user.

deviceToken

Data?

Device token used for push notifications for this user.

completion

(Error?, PlayPortalProfile?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

anonymousUser

PlayPortalProfile?

The anonymous user created for a successful request.