Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RudderSdk.Core.Models.Stores;
|
||||
|
||||
namespace RudderSdk.Core;
|
||||
|
||||
/// <summary>In-game stores and offer purchases.</summary>
|
||||
public sealed class StoresService
|
||||
{
|
||||
private readonly RudderClient _client;
|
||||
|
||||
internal StoresService(RudderClient client) => _client = client;
|
||||
|
||||
/// <summary>Lists the available stores with their offers.</summary>
|
||||
public async Task<IReadOnlyList<Store>> ListAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await _client.SendAsync<ListStoresResponse>(
|
||||
"GET",
|
||||
"/sdk/v1/stores",
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return response?.Stores ?? new List<Store>();
|
||||
}
|
||||
|
||||
/// <summary>Resolves one store by slug.</summary>
|
||||
public Task<Store> GetAsync(string slug, CancellationToken cancellationToken = default)
|
||||
=> _client.SendAsync<Store>("GET", "/sdk/v1/stores/" + Url.Encode(slug), cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Purchases an offer (charges the wallet). When
|
||||
/// <paramref name="idempotencyKey"/> is null, a random one is generated;
|
||||
/// pass a stable key to make retries safe.
|
||||
/// </summary>
|
||||
public Task<PurchaseOfferResponse> PurchaseAsync(
|
||||
string storeSlug,
|
||||
string offerId,
|
||||
string? idempotencyKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _client.SendAsync<PurchaseOfferRequest, PurchaseOfferResponse>(
|
||||
"POST",
|
||||
"/sdk/v1/stores/" + Url.Encode(storeSlug) + "/offers/" + Url.Encode(offerId) + "/purchase",
|
||||
new PurchaseOfferRequest
|
||||
{
|
||||
StoreSlug = storeSlug,
|
||||
OfferId = offerId,
|
||||
IdempotencyKey = idempotencyKey ?? Guid.NewGuid().ToString()
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user