UpdateSingleton
Method updates a singleton entity on the server. This operation results in the entity data being completely replaced by the passed in JSON string. If the entity doesn't exist it is created.
Singletons are defined by their entity type, so no two singletons of the same type can exist at once.
This method is affected by versioning. See the versioning documentation for more information.
Service | Operation |
---|---|
entity | UPDATE_SINGLETON |
Method Parameters
Parameter | Description |
---|---|
entityType | The entity type as defined by the user |
data | The entity's data object |
acl | The entity's Access Control List as object. A null ACL implies default permissions which make the entity readable/writeable by only the user. |
version | The version of the entity to update. Use -1 to indicate the newest version |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string entityType = "settings";
string jsonEntityData = "{\"difficulty\":\"normal\"}";
string jsonEntityAcl = "{\"other\":0}";
int version = -1;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.EntityService.UpdateSingleton(entityType, jsonEntityData, jsonEntityAcl, version, successCallback, failureCallback);
const char *entityType = "settings";
const char *jsonEntityData = "{\"difficulty\":\"normal\"}";
const char *jsonEntityAcl = "{\"other\":0}";
int version = -1;
_bc->getEntityService()->updateSingleton(entityType, jsonEntityData, jsonEntityAcl, version, this);
NSString *entityType = @"settings";
NSString *jsonEntityData = @"{\"difficulty\":\"normal\"}";
NSString *jsonEntityAcl = @"{\"other\":0}";
int version = -1;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc entityService] updateSingleton:entityType
jsonEntityData:jsonEntityData
jsonEntityAcl:jsonEntityAcl
version:version
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String entityType = "settings";
String jsonEntityData = "{\"difficulty\":\"normal\"}";
String jsonEntityAcl = "{\"other\":0}";
int version = -1;
this; // implements IServerCallback
_bc.getEntityService().updateSingleton(entityType, jsonEntityData, jsonEntityAcl, version, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var entityType = "settings";
var jsonEntityData = {
"difficulty": "normal"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
_bc.entity.updateSingleton(entityType, jsonEntityData, jsonEntityAcl, version, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var entityType = "settings";
var jsonEntityData = {
"difficulty": "normal"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
ServerResponse result = await _bc.entityService.updateSingleton(entityType:entityType, jsonEntityData:jsonEntityData, jsonEntityAcl:jsonEntityAcl, version:version);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var entityType = "settings";
var jsonEntityData = {
"difficulty": "normal"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
var entityProxy = bridge.getEntityServiceProxy();
var postResult = entityProxy.updateSingleton(entityType, jsonEntityData, jsonEntityAcl, version);
if (postResult.status == 200) {
// Success!
}
{
"service": "entity",
"operation": "UPDATE_SINGLETON",
"data": {
"entityType": "settings",
"data": {
"difficulty": "normal"
},
"acl": {
"other": 0
},
"version": -1
}
}
JSON Response
{
"status": 200,
"data": {
"entityType": "test",
"version": 1 // Note - `version` will only be returned if not null or -1 in the update call
}
}