Profile operations
Profile operations are responsible for communicating with the Profile API.
Each method that works with statistical data also converts your IDs to the desired ID provider for easier and quicker development.
The general design of the namespace follows this pattern:
val response = sdk.profile().someMethod(...)
// do something with response object
Profile related operations
Profile related operations are always prefixed by one of two methods: getOwn() or getById(). These fetch the user object you will be working with.
Depending on the object you are allowed to perform different actions. For instance, you can perform unsafe operations (ex. update) only on the user's own profile.
This means that addInterest(), removeInterest() and so on can only follow the getOwn() method.
Keep in mind that all responses following getById() are cached for an hour by the API. The responses following getOwn(), while not cached by the API are saved locally inside the SDK (local storage) and updated every 10 minutes.
Get user info
Method: getInfo()
The user info is returned by the getInfo() method. It can be used only after getOwn() or getById(). Note that profile response model does not have interests property.
// Getting the user's own profile
val profile = sdk.profile().getOwn()
// Getting other user's profile
val profile = sdk.profile().getById("user-id")
val id = profile.id
val avatar = profile.avatar
val name = profile.name
val nickname = profile.nickname
val country = profile.country
val gender = profile.gender
val birthDate = profile.birthDate
val interests = profile.interests
val followingCount = profile.followingCount
val followersCount = profile.followersCount
val createdAt = profile.createdAt
Get users by user IDs
Method: getByIds(["user-id"], disableCache?)
This method allows developers to fetch multiple user profiles at once.
If no value is passed to disableCache (undefined) it will be set to false.
// Getting other user's profile
val response = sdk.profile().getByIds(listOf("mebraVQWHxP6MBrhFbwTxto89x33","user-id-2"))
val profilesList = response.data
Set birthdate, gender, country, nickname and name
Method: setBirthdate(""), setGender(""), setCountry(""), setNickname("") & setName("")
Updating the user's profile happens with a few different methods, depending on what you want to update. Each of those methods must follow only the getOwn() method. At the end, the developer needs to call the update() method to commit the changes.
sdk.profile().getOwn()
.setBirthdate("1991-03-24") // Format "YYYY-MM-DD"
.setGender(Gender) // Options are: Gender.MALE, Gender.FEMALE, Gender.UNSPECIFIED
.setCountry("profile:cnt:113") // Valid country ID from the Profile API
.setName("Lorem Ipsum")
.setNickname("lorem")
.update();
The update() method performs an update to the backend. Resolved response represents same model as getInfo() method.
Show profile fullness
Method: showFullnessProfile()
This method returns the fullness of the profile in percent and details how many percent each action is rewarded with.
// Getting the user's own profile fullness
val response = sdk.profile().showOwnFullnessProfile()
// Getting other user's fullness profile
val response = sdk.profile().showFullnessProfile("user-id")
Interests related operations
Interests, like profile related operations, work with the object provided by the getOwn() and getById() methods.
Show interests
Method: showInterests()
Raw interests data is available via the showInterests() method. Keep in mind that each interest id should match id schema provided in SDK's configuration.
// Getting the user's own interests
val interests: List<Interest> = sdk.profile().showOwnInterests()
// Getting other user's interests
val interests: List<Interest> = sdk.profile().showInterests('user-id')
Show full interests
Method: showFullInterests()
In case you want to get all the entities data related to the interests, you can use showOwnFullInterests() and showFullInterests(userId). This will return not only the IDs, but the model as well (names, photos, country, etc.). In addition it will convert any ID to the desired provider.
// Getting the user's own interests, but with all the entities attached
val interests: List<FullInterest> = sdk.profile().getOwn().showOwnFullInterests()
// Getting other user's interests, but with all the entities attached
val interests: List<FullInterest> = sdk.profile().getById('user-id').showFullInterests("user-id")
Add interest
Method: addInterest({})
Users can add interests only to their own profiles. This happens with the addInterest() method which follows getOwn(). The addInterest() method can be chained allowing developers to send multiple interests at the same time.
Just like the update of the profile, the developer needs to finally call the update() method.
// User adding interests to their profile
val updatedProfile = sdk.profile().getOwn()
.addInterest({
source: InterestSource.FOOTBALL, // enum InterestSource
type: Type.TEAM, // enum Type
id: "102",
favourite: false
})
.addInterest({
source: InterestSource.FOOTBALL,
type: Type.PLAYER,
id: "3400",
favourite: false
})
.update();
Remove interest
Method: removeInterest({})
Users can remove interests from their own profiles. This happens with the removeInterest() method which follows getOwn(). The removeInterest() method can be chained allowing developers to remove multiple interests at the same time.
Just like the update of the profile, the developer needs to finally call the update() method.
// User removing interests from their profile
val updatedProfile = sdk.profile().getOwn()
.removeInterest({
source: InterestSource.FOOTBALL,
type: Type.TEAM,
id: "102",
favourite: false
})
.removeInterest({
source: InterestSource.FOOTBALL,
type: Type.PLAYER,
id: "3400",
favourite: false
})
.update();
Follower related operations
Get followers & following
Method: getOwnFollowers(), getOwnFollowing(), getFollowers() & getFollowing()
These methods allow the developers to fetch the lists of followers and following users for one's own or a specified profile. These methods support pagination. The developer can specified how many users to be fetched, as well as specify after which User ID to start.
// Getting 10 of the user's own followers, starting after user with ID "c9KSw6UscWe9iNWCvcb12blNShi2"
val response: List<PartialProfile> = sdk.profile().getOwnFollowers({
limit: 10,
startAfter: "c9KSw6UscWe9iNWCvcb12blNShi2"
})
// Getting the users followed by the currently logged user
val response: List<PartialProfile> = sdk.profile().getOwnFollowing()
// Getting a specified user's followers
val response: List<PartialProfile> = sdk.profile().getFollowers({
userId: "user-id",
limit: 10,
startAfter: "c9KSw6UscWe9iNWCvcb12blNShi2"
})
// profile() a list of users followed by a specified user
val response: List<PartialProfile> = sdk.profile().getFollowing("user-id")
Follow user
Method: follow(userIds)
This method allows users to follow other users. In the request the users that are being followed are listed as an array of user IDs.
In the response we return user objects of the followed users.
NB: If you send a request to follow a user that is already being followed, that user will not be returned in the response (it will return an empty array []
).
val followedProfiles: List<PartialProfile> = sdk
.profile()
.follow(listOf("2Blge85wjjecpG3bMEMjzieLgTz1", "YP3SKSzPRlVOBNtv4xssnCnGUQP2"))
Unfollow user
Method: unfollow(userIds)
By passing an array of user IDs, the user can unfollow a list of users at once. On success, we will return "true" in the promise.
// unfollow method doesn't return result. If success it won't throw an exception
sdk.profile().unfollow(listOf("2Blge85wjjecpG3bMEMjzieLgTz1", "YP3SKSzPRlVOBNtv4xssnCnGUQP2"))
Points, tiers and badges opeartions
Get profile stats
Method: getOwnStats() and getStats(userId)
Returns points, tier and success rates for own or specified profile.
// Get own profile points and tier
val stats: ProfileStats? = sdk.profile().getOwnStats()
// Get specified profile points and tier
val stats: ProfileStats? = sdk.profile().getStats("tyuaMEKdleSzyPniKcXdoM0mviK2")
Get profile badges
Method: getOwnBadges and getBadges(userId)
Returns list of aquired badges for own or specified profile.
// Get own profile badges
val badges: List<String> = sdk.profile().getOwnBadges()
// Get specified profile badges
val badges: List<String> = sdk.profile().getBadges("tyuaMEKdleSzyPniKcXdoM0mviK2")
Other operations
Get countries
Method: getCountries(language, disableCache?)
This method fetches countries. Unlike the "football countries", these are the actual political entities. Countries like "England" and "Scotland" are missing and replaced by "Great Britain".
language
field defaults to SDK's config.lang
If no value is passed to disableCache
defaults to false
.
val countries = sdk.profile().getCountries()
Updated about 1 year ago