-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCards.cs
More file actions
41 lines (31 loc) · 1.44 KB
/
Copy pathCards.cs
File metadata and controls
41 lines (31 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using ScryfallApi.Client.Models;
using System.Net;
using static ScryfallApi.Client.Models.SearchOptions;
namespace ScryfallApi.Client.Apis;
///<inheritdoc cref="ICards"/>
public class Cards : ICards
{
private readonly BaseRestService _restService;
internal Cards(BaseRestService restService)
{
_restService = restService;
}
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public Task<ResultList<Card>> Get(int page) => _restService.GetAsync<ResultList<Card>>($"/cards?page={page}");
public Task<Card> GetRandom() => _restService.GetAsync<Card>($"/cards/random", false);
public Task<Card> Named(string cardname, bool fuzzySearch)
{
cardname = WebUtility.UrlEncode(cardname);
var searchType = fuzzySearch ? "fuzzy" : "exact";
return _restService.GetAsync<Card>($"/cards/named?{searchType}={cardname}");
}
public Task<ResultList<Card>> Search(string query, int page, CardSort sort) =>
Search(query, page, new SearchOptions { Sort = sort });
public Task<ResultList<Card>> Search(string query, int page, SearchOptions options = default)
{
if (page < 1) page = 1;
query = WebUtility.UrlEncode(query);
return _restService.GetAsync<ResultList<Card>>($"/cards/search?q={query}&page={page}&{options.BuildQueryString()}");
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}