App Context API for PubNub Unreal SDK
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.
PubNub also triggers events when object data is set or removed from the database. Clients can receive these events in real time and update their front-end application accordingly.
User
Get Metadata for All Users
Returns a paginated list of User Metadata objects, optionally including the custom data object for each.
Method(s)
- Blueprint
- C++
Response variants
You can also call the GetAllUserMetadata_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
Response variants
You can also call the GetAllUserMetadata_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
PubnubSubsystem->GetAllUserMetadata(
FString Include,
int Limit,
FString Filter
FString Sort
FString PageNext,
FString PagePrev,
EPubnubTribool Count,
FOnGetAllUserMetadataResponse OnGetAllUserMetadataResponse
);
Parameter | Type | Required | Description |
---|---|---|---|
Include | FString | Optional | A comma delimited string with additional/complex user attributes to include in response. Use "" if you don't want to retrieve additional attributes. |
Limit | int | Optional | Number of objects to return in response. Available values: 1 - 100 . If you set 0 , the default value of 100 is used. |
Filter | FString | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
Sort | FString | Optional | Key-value pair of a property to sort by, and a sort direction. Available options are id , name , and updated . Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending). For example: {name: 'asc'} |
PageNext | FString | Optional | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
PagePrev | FString | Optional | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the PageNext parameter is supplied. |
Count | EPubnubTribool enum | Yes | Total request count to be included in paginated response. By default, the total count is omitted. Available values:
|
OnGetAllUserMetadataResponse | FOnGetAllUserMetadataResponse | Yes | The callback function used to handle the result. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString Channel = "randomChannel";
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnGetAllUserMetadataResponse OnGetAllUserMetadataResponse;
OnGetAllUserMetadataResponse.BindDynamic(this, &AMyActor::OnGetAllUserMetadataResponse);
int Limit = 10; // Limit to 10 objects
EPubnubTribool Count = PT_False; // Don't include total count
show all 17 linesReturns
This method returns the FOnGetAllUserMetadataResponse
struct.
FOnGetAllUserMetadataResponse
Field | Type | Description |
---|---|---|
Status | int | HTTP code of the result of the operation. |
UsersData | TArray<FPubnubUserData>& | Aa array of FPubnubUserData structs which are the users with their associated User metadata. |
PageNext | FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
PagePrev | FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the pageNext parameter is supplied. |
FPubnubUserData
Field | Type | Description |
---|---|---|
UserID | FString | Unique user identifier. If not supplied, then the current user's User is used. |
UserName | FString | Display name for the user. |
ExternalID | FString | User's identifier in an external system. |
ProfileUrl | FString | The URL of the user's profile picture. |
Email | FString | The user's email address. |
Custom | FString | JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. |
Status | FString | User status. Max. 50 characters. |
Type | FString | User type. Max. 50 characters. |
Updated | FString | The date when the user's metadata was last updated. |
ETag | FString | Information on the object's content fingerprint. |
JSON Response
{
"Uuids": [
{
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "john.doe@pubnub.com",
"ExternalId": "",
"ProfileUrl": "",
"Custom": "",
"Updated": "2020-06-17T16:28:14.060718Z"
},
{
"Uuid": "uuid-2",
"Name": "Bob Cat",
"Email": "bobc@example.com",
show all 29 linesGet User Metadata
Returns metadata for the specified User, optionally including the custom data object for each.
Method(s)
- Blueprint
- C++
Response variants
You can also call the GetUserMetadata_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
Response variants
You can also call the GetUserMetadata_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
PubnubSubsystem->GetUserMetadata(
FString Include,
FString User,
FOnGetUserMetadataResponse OnGetUserMetadataResponse
);
Parameter | Type | Required | Description |
---|---|---|---|
Include | FString | Optional | A comma delimited string with additional/complex user attributes to include in response. Use "" if you don't want to retrieve additional attributes. |
User | FString | Optional | The metadata ID for which to retrieve the user object. Can't be empty. |
OnGetUserMetadataResponse | FOnGetUserMetadataResponse | Yes | The callback function used to handle the result. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnGetUserMetadataResponse OnGetUserMetadataResponse;
OnGetUserMetadataResponse.BindDynamic(this, &AMyActor::OnGetUserMetadataResponse);
FString Include = ""; // No additional attributes
FString User = "uuid-1";
PubnubSubsystem->GetUserMetadata(Include, Limit, Start, End, Count, OnGetUserMetadataResponse);
Returns
This method returns the FOnGetUserMetadataResponse
struct.
FOnGetUserMetadataResponse
Field | Type | Description |
---|---|---|
Status | int | HTTP code of the result of the operation. |
UserData | FPubnubUserData | Aa instance of FPubnubUserData struct which is the user with their associated User metadata. |
JSON Response
{
"Uuid": "uuid-1",
"Name": "John Doe",
"Email": "john.doe@pubnub.com",
"ExternalId": "",
"ProfileUrl": "",
"Custom": "",
"Updated": "2020-06-17T16:28:14.060718Z"
}
Set User Metadata
Set metadata for a User in the database, optionally including the custom data object for each.
Method(s)
- Blueprint
- C++
PubnubSubsystem->SetUserMetadata(
FString User,
FString Include,
FString UserMetadataObj
);
Parameter | Type | Required | Description |
---|---|---|---|
User | FString | Optional | The metadata ID for which to retrieve the user object. Can't be empty. |
Include | FString | Optional | A comma delimited string with additional/complex user attributes to include in response. Use "" if you don't want to retrieve additional attributes. |
UserMetadataObj | FString | Optional | The JSON string with the definition of the User Metadata object to create. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString User = "user123"; // Example User Metadata ID
FString Include = ""; // No additional attributes
FString UserMetadataObj = "{\"name\":\"John Doe\",\"email\":\"johndoe@example.com\"}"; // Example JSON object
// Call the SetUserMetadata method
PubnubSubsystem->SetUserMetadata(User, Include, UserMetadataObj);