diff --git a/samples/ScryfallApi.WebSample/Pages/Named.cshtml b/samples/ScryfallApi.WebSample/Pages/Named.cshtml new file mode 100644 index 0000000..88aba2b --- /dev/null +++ b/samples/ScryfallApi.WebSample/Pages/Named.cshtml @@ -0,0 +1,49 @@ +@page +@model NamedModel +@{ +} + +

Named

+
+
+

+ Search Query: +

+
+
+
+ Name: + +
+
+
+
+@if (@Model?.NamedCard != null) +{ +

Result: @Model.NamedCard.Name

+
+
+ + @if (Model.NamedCard.Layout.Equals("transform", StringComparison.OrdinalIgnoreCase)) + { + foreach (var face in Model.NamedCard.CardFaces) + { + + } + } + else + { + + } + +
+
+} +else +{ +
+
+

No cards found!

+
+
+} diff --git a/samples/ScryfallApi.WebSample/Pages/Named.cshtml.cs b/samples/ScryfallApi.WebSample/Pages/Named.cshtml.cs new file mode 100644 index 0000000..1556de7 --- /dev/null +++ b/samples/ScryfallApi.WebSample/Pages/Named.cshtml.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using ScryfallApi.Client; +using ScryfallApi.Client.Models; + +namespace ScryfallApi.WebSample.Pages +{ + public class NamedModel : PageModel + { + ScryfallApiClient _scryfallApi { get; } + public Card NamedCard { get; set; } + + [BindProperty] + public string Query { get; set; } + + public NamedModel(ScryfallApiClient scryfallApi) + { + _scryfallApi = scryfallApi ?? throw new ArgumentNullException(nameof(scryfallApi)); + } + + public void OnGet() + { + } + + public async Task OnPostAsync() + { + NamedCard = await _scryfallApi.Cards.Named(Query, true); + return Page(); + } + } +} \ No newline at end of file diff --git a/src/ScryfallApi.Client/Apis/Cards.cs b/src/ScryfallApi.Client/Apis/Cards.cs index 2375a9c..cca5f76 100644 --- a/src/ScryfallApi.Client/Apis/Cards.cs +++ b/src/ScryfallApi.Client/Apis/Cards.cs @@ -19,6 +19,13 @@ internal Cards(BaseRestService restService) public Task GetRandom() => _restService.GetAsync($"/cards/random", false); + public Task Named(string cardname, bool fuzzySearch) + { + cardname = WebUtility.UrlEncode(cardname); + var searchType = fuzzySearch ? "fuzzy" : "exact"; + return _restService.GetAsync($"/cards/named?{searchType}={cardname}"); + } + public Task> Search(string query, int page, CardSort sort) => Search(query, page, new SearchOptions { Sort = sort }); @@ -29,5 +36,6 @@ public Task> Search(string query, int page, SearchOptions optio query = WebUtility.UrlEncode(query); return _restService.GetAsync>($"/cards/search?q={query}&page={page}&{options.BuildQueryString()}"); } + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } diff --git a/src/ScryfallApi.Client/Apis/ICards.cs b/src/ScryfallApi.Client/Apis/ICards.cs index 61097b2..8c4582f 100644 --- a/src/ScryfallApi.Client/Apis/ICards.cs +++ b/src/ScryfallApi.Client/Apis/ICards.cs @@ -22,6 +22,14 @@ public interface ICards /// Task> Get(int page); + /// + /// Search for exactly one card of the given name. Search parameters can be either exact or fuzzy. + /// + /// + /// + /// + Task Named(string cardname, bool fuzzySearch); + /// /// Search for cards with a sort option /// @@ -39,4 +47,5 @@ public interface ICards /// /// Task> Search(string query, int page, SearchOptions options); + }