Adds methods to fetch cards
This commit is contained in:
parent
e6c7cdf9b4
commit
b6ff5f86a6
|
@ -9,6 +9,7 @@ using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JpnCardsPokemonSdk.Api;
|
using JpnCardsPokemonSdk.Api;
|
||||||
using JpnCardsPokemonSdk.Client.Responses;
|
using JpnCardsPokemonSdk.Client.Responses;
|
||||||
|
using JpnCardsPokemonSdk.Utils.QueryFilter;
|
||||||
|
|
||||||
namespace JpnCardsPokemonSdk.Client;
|
namespace JpnCardsPokemonSdk.Client;
|
||||||
|
|
||||||
|
@ -95,6 +96,29 @@ public class ApiClient
|
||||||
return await FetchInternalAsync<Set>(SetQuery($"uuid/{uuid}"));
|
return await FetchInternalAsync<Set>(SetQuery($"uuid/{uuid}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Card>> FetchCardsAsync(string query)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
throw new Exception("Query string required");
|
||||||
|
|
||||||
|
// JSON response is wrapped into a data property, so we parse as JsonDocument first before deserialization.
|
||||||
|
var options = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true,
|
||||||
|
IncludeFields = true,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||||
|
};
|
||||||
|
|
||||||
|
var jsonData = await FetchInternalAsync<JsonDocument>($"card/{query}");
|
||||||
|
return jsonData?.RootElement.GetProperty("data").Deserialize<IEnumerable<Card>>(options) ??
|
||||||
|
Enumerable.Empty<Card>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Card>?> FetchCardsAsync(IQueryFilterBuilder filterBuilder)
|
||||||
|
{
|
||||||
|
return await FetchCardsAsync(filterBuilder.BuildQueryString());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public async Task<EnumerableApiResponse<T>?> FetchDataAsync<T>(string? query = null, int page = 1)
|
public async Task<EnumerableApiResponse<T>?> FetchDataAsync<T>(string? query = null, int page = 1)
|
||||||
where T : EndpointObject
|
where T : EndpointObject
|
||||||
|
|
Loading…
Reference in a new issue