Add ProjectStorageService and generated ProjectStorage models
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RudderSdk.Core.Models.ProjectStorage;
|
||||
|
||||
public class GetProjectStorageResponse
|
||||
{
|
||||
[JsonProperty("items")]
|
||||
public List<ProjectStorageItem> Items { get; set; }
|
||||
|
||||
[JsonProperty("nextCursor")]
|
||||
public string NextCursor { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RudderSdk.Core.Models.ProjectStorage;
|
||||
|
||||
public class ProjectStorageItem
|
||||
{
|
||||
[JsonProperty("data")]
|
||||
public string Data { get; set; }
|
||||
|
||||
[JsonProperty("expiresAt")]
|
||||
public string ExpiresAt { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty("readPermission")]
|
||||
public string ReadPermission { get; set; }
|
||||
|
||||
[JsonProperty("size")]
|
||||
public long Size { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("updatedAt")]
|
||||
public string UpdatedAt { get; set; }
|
||||
|
||||
[JsonProperty("version")]
|
||||
public long Version { get; set; }
|
||||
|
||||
[JsonProperty("writePermission")]
|
||||
public string WritePermission { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RudderSdk.Core.Models.ProjectStorage;
|
||||
|
||||
public class ProjectStorageUpdateItem
|
||||
{
|
||||
[JsonProperty("data")]
|
||||
public string Data { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Code generated by apigen. DO NOT EDIT.
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RudderSdk.Core.Models.ProjectStorage;
|
||||
|
||||
public class UpdateProjectStorageRequest
|
||||
{
|
||||
[JsonProperty("idempotencyKey")]
|
||||
public string IdempotencyKey { get; set; }
|
||||
|
||||
[JsonProperty("items")]
|
||||
public List<ProjectStorageUpdateItem> Items { get; set; }
|
||||
|
||||
}
|
||||
@@ -29,6 +29,9 @@ public sealed class RudderClient
|
||||
/// <summary>Player key-value storage.</summary>
|
||||
public StorageService Storage { get; }
|
||||
|
||||
/// <summary>Project key-value storage (global, shared across players).</summary>
|
||||
public ProjectStorageService ProjectStorage { get; }
|
||||
|
||||
/// <summary>In-game stores and offer purchases.</summary>
|
||||
public StoresService Stores { get; }
|
||||
|
||||
@@ -86,6 +89,7 @@ public sealed class RudderClient
|
||||
Player = new PlayerService(this);
|
||||
RemoteConfig = new RemoteConfigService(this);
|
||||
Storage = new StorageService(this);
|
||||
ProjectStorage = new ProjectStorageService(this);
|
||||
Stores = new StoresService(this);
|
||||
Leaderboards = new LeaderboardsService(this);
|
||||
Inventory = new InventoryService(this);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RudderSdk.Core.Models.ProjectStorage;
|
||||
|
||||
namespace RudderSdk.Core;
|
||||
|
||||
/// <summary>Project key-value storage (global, shared across players).</summary>
|
||||
public sealed class ProjectStorageService
|
||||
{
|
||||
private readonly RudderClient _client;
|
||||
|
||||
internal ProjectStorageService(RudderClient client) => _client = client;
|
||||
|
||||
/// <summary>Fetches one page of project storage items, optionally filtered by type.</summary>
|
||||
public Task<GetProjectStorageResponse> GetAsync(string? type = null, int limit = 100, string? cursor = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = Url.Query(
|
||||
("types", type),
|
||||
("limit", limit > 0 ? limit.ToString() : null),
|
||||
("cursor", cursor));
|
||||
|
||||
return _client.SendAsync<GetProjectStorageResponse>("GET", "/sdk/v1/project-storage" + query, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Iterates over all project storage items, following the cursor pagination.</summary>
|
||||
public async IAsyncEnumerable<ProjectStorageItem> ListAllAsync(
|
||||
string? type = null,
|
||||
int limit = 100,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
string? cursor = null;
|
||||
do
|
||||
{
|
||||
var page = await GetAsync(type, limit, cursor, cancellationToken).ConfigureAwait(false);
|
||||
if (page?.Items != null)
|
||||
{
|
||||
foreach (var item in page.Items)
|
||||
yield return item;
|
||||
}
|
||||
|
||||
cursor = page?.NextCursor;
|
||||
}
|
||||
while (!string.IsNullOrEmpty(cursor));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves (upserts) project storage items. When
|
||||
/// <paramref name="idempotencyKey"/> is null, a random one is generated.
|
||||
/// </summary>
|
||||
public Task SaveAsync(IEnumerable<ProjectStorageUpdateItem> items, string? idempotencyKey = null, CancellationToken cancellationToken = default)
|
||||
=> _client.SendAsync(
|
||||
"PUT",
|
||||
"/sdk/v1/project-storage",
|
||||
new UpdateProjectStorageRequest
|
||||
{
|
||||
IdempotencyKey = idempotencyKey ?? Guid.NewGuid().ToString(),
|
||||
Items = items?.ToList() ?? new List<ProjectStorageUpdateItem>()
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
Reference in New Issue
Block a user