public async Task Operations(string initialValue, DatastoreOperation operation, string updateValue, string expectedValue) { const string key = "__Test__Operations"; Assert.That((await Api.Datastore.SetAsync(key, initialValue)).Success); var result = await Api.Datastore.UpdateAsync(key, updateValue, operation); Assert.That(result.Success); Assert.That(result.Data == expectedValue); Assert.That((await Api.Datastore.RemoveAsync(key)).Success); }
/// <summary> /// Updates data in the data store. On success, the new value of the data item is returned. /// Caution: GameJolt has a hard limit of 16MB per key-value pair and a soft limit of 1MB per post-request. /// </summary> /// <param name="key">The key of the data item you'd like to update.</param> /// <param name="data">The value you'd like to apply to the data store item. </param> /// <param name="operation">The operation you'd like to perform. /// Add, Subtract, Multiply and Divide are only applicable to numeric values.</param> /// <param name="credentials">If you pass in the user information, this function will use the user's data store. /// If you leave the user information empty, it will use the game's global data store.</param> /// <returns></returns> public async Task <Response <string> > UpdateAsync([NotNull] string key, [NotNull] string data, DatastoreOperation operation, Credentials credentials = null) { key.ThrowIfNullOrEmpty(); data.ThrowIfNull(); var parameters = new Dictionary <string, string> { { "operation", operation.ToString().ToLower() } }; if (credentials != null) { parameters.Add("username", credentials.Name); parameters.Add("user_token", credentials.Token); } return(await Api.PostDumpAsync("/data-store/update", parameters, new Dictionary <string, string> { { "key", key }, { "value", data } })); }
public void Update([NotNull] string key, [NotNull] string data, DatastoreOperation operation, Credentials credentials = null, Action <Response <string> > callback = null) { Wrap(UpdateAsync(key, data, operation, credentials), callback); }