Skip to content

Commit 2c14ca2

Browse files
committed
Merge branch 'euronay-master'
2 parents ea62530 + 35a9afd commit 2c14ca2

File tree

7 files changed

+133
-123
lines changed

7 files changed

+133
-123
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@page
2+
@model SearchModel
3+
@{
4+
}
5+
6+
<h2>Search</h2>
7+
<div class="row">
8+
<div class="col-md-12">
9+
<p>
10+
Search Query:
11+
</p>
12+
<div asp-validation-summary="All"></div>
13+
<form method="POST">
14+
<div>Name: <input asp-for="Query" />
15+
<input type="submit" value="Search" />
16+
</div>
17+
</form>
18+
</div>
19+
</div>
20+
@if(@Model.Results != null)
21+
{
22+
@foreach(var card in @Model.Results?.Data)
23+
{
24+
<h3>Result: <a href="@card.ScryfallUri">@card.Name</a></h3>
25+
<div class="row">
26+
<div class="col-md-12">
27+
<a href="@card.ScryfallUri">
28+
@if (card.Layout.Equals("transform", StringComparison.OrdinalIgnoreCase))
29+
{
30+
foreach (var face in card.CardFaces)
31+
{
32+
<img src="@face.ImageUris["normal"]" style="max-width: 320px;" />
33+
}
34+
}
35+
else
36+
{
37+
<img src="@card.ImageUris["normal"]" style="max-width: 320px;" />
38+
}
39+
</a>
40+
</div>
41+
</div>
42+
}
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using ScryfallApi.Client;
8+
using ScryfallApi.Client.Models;
9+
10+
namespace ScryfallApi.WebSample.Pages
11+
{
12+
public class SearchModel : PageModel
13+
{
14+
ScryfallApiClient _scryfallApi { get; }
15+
16+
[BindProperty]
17+
public ResultList<Card> Results { get; set; }
18+
19+
[BindProperty]
20+
public string Query {get; set;}
21+
22+
public SearchModel(ScryfallApiClient scryfallApi)
23+
{
24+
_scryfallApi = scryfallApi ?? throw new ArgumentNullException(nameof(scryfallApi));
25+
}
26+
27+
public void OnGet()
28+
{
29+
}
30+
31+
public async Task<ActionResult> OnPostAsync()
32+
{
33+
Results = await _scryfallApi.Cards.Search(Query, 1, CardSort.Cmc );
34+
35+
return Page();
36+
}
37+
}
38+
}

samples/ScryfallApi.WebSample/Pages/Shared/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<div class="navbar-collapse collapse">
3232
<ul class="nav navbar-nav">
3333
<li><a asp-page="/Index">Home</a></li>
34+
<li><a asp-page="/Search">Search</a></li>
3435
</ul>
3536
</div>
3637
</div>

src/ScryfallApi.Client/Apis/Cards.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ internal Cards(HttpClient httpClient, ILogger logger, IMemoryCache cache = null)
1414
public async Task<ResultList<Card>> Get(int page) => await GetAsync<ResultList<Card>>($"/cards?page={page}");
1515
public async Task<Card> GetRandom() => await GetAsync<Card>($"/cards/random", false);
1616

17-
18-
19-
public Task<ResultList<Card>> Search(string query, int page, CardSort sort) => throw new NotImplementedException();
17+
//TODO : Add more search options,
18+
public async Task<ResultList<Card>> Search(string query, int page, CardSort sort = CardSort.Cmc) => await GetAsync<ResultList<Card>>($"/cards/search?q={query}&page={page}&order={sort.ToString().ToLowerInvariant()}");
2019
}
2120
}

src/ScryfallApi.Client/Models/Card.cs

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -289,119 +289,4 @@ public override string ToString() => Name +
289289
(!string.IsNullOrWhiteSpace(ManaCost) ? $" ({ManaCost})" : "") +
290290
(!string.IsNullOrWhiteSpace(TypeLine) ? $" {TypeLine}" : "");
291291
}
292-
293-
294-
295-
public class Rootobject
296-
{
297-
public string _object { get; set; }
298-
public int total_cards { get; set; }
299-
public bool has_more { get; set; }
300-
public string next_page { get; set; }
301-
public Datum[] data { get; set; }
302-
}
303-
304-
public class Datum
305-
{
306-
public string _object { get; set; }
307-
public string id { get; set; }
308-
public int?[] multiverse_ids { get; set; }
309-
//public string name { get; set; }
310-
//public string uri { get; set; }
311-
public string scryfall_uri { get; set; }
312-
public string layout { get; set; }
313-
public bool highres_image { get; set; }
314-
public Image_Uris image_uris { get; set; }
315-
public int cmc { get; set; }
316-
public string type_line { get; set; }
317-
public string oracle_text { get; set; }
318-
public string mana_cost { get; set; }
319-
public string[] colors { get; set; }
320-
public string[] color_identity { get; set; }
321-
public Legalities legalities { get; set; }
322-
public bool reserved { get; set; }
323-
public bool reprint { get; set; }
324-
public string set { get; set; }
325-
public string set_name { get; set; }
326-
public string set_uri { get; set; }
327-
public string set_search_uri { get; set; }
328-
public string scryfall_set_uri { get; set; }
329-
public string rulings_uri { get; set; }
330-
public string prints_search_uri { get; set; }
331-
public string collector_number { get; set; }
332-
public bool digital { get; set; }
333-
public string rarity { get; set; }
334-
public string watermark { get; set; }
335-
public string flavor_text { get; set; }
336-
public string illustration_id { get; set; }
337-
public string artist { get; set; }
338-
public string frame { get; set; }
339-
public bool full_art { get; set; }
340-
public string border_color { get; set; }
341-
public bool timeshifted { get; set; }
342-
public bool colorshifted { get; set; }
343-
public bool futureshifted { get; set; }
344-
public int edhrec_rank { get; set; }
345-
public string usd { get; set; }
346-
public string eur { get; set; }
347-
public Related_Uris related_uris { get; set; }
348-
public Purchase_Uris purchase_uris { get; set; }
349-
public string[] color_indicator { get; set; }
350-
public All_Parts[] all_parts { get; set; }
351-
}
352-
353-
public class Image_Uris
354-
{
355-
public string small { get; set; }
356-
public string normal { get; set; }
357-
public string large { get; set; }
358-
public string png { get; set; }
359-
public string art_crop { get; set; }
360-
public string border_crop { get; set; }
361-
}
362-
363-
public class Legalities
364-
{
365-
public string standard { get; set; }
366-
public string frontier { get; set; }
367-
public string modern { get; set; }
368-
public string pauper { get; set; }
369-
public string legacy { get; set; }
370-
public string penny { get; set; }
371-
public string vintage { get; set; }
372-
public string duel { get; set; }
373-
public string commander { get; set; }
374-
public string _1v1 { get; set; }
375-
public string future { get; set; }
376-
}
377-
378-
public class Related_Uris
379-
{
380-
public string gatherer { get; set; }
381-
public string tcgplayer_decks { get; set; }
382-
public string edhrec { get; set; }
383-
public string mtgtop8 { get; set; }
384-
}
385-
386-
public class Purchase_Uris
387-
{
388-
public string amazon { get; set; }
389-
public string ebay { get; set; }
390-
public string tcgplayer { get; set; }
391-
public string magiccardmarket { get; set; }
392-
public string cardhoarder { get; set; }
393-
public string card_kingdom { get; set; }
394-
public string mtgo_traders { get; set; }
395-
public string coolstuffinc { get; set; }
396-
}
397-
398-
public class All_Parts
399-
{
400-
public string _object { get; set; }
401-
public string id { get; set; }
402-
public string name { get; set; }
403-
public string uri { get; set; }
404-
}
405-
406-
407292
}
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
24

35
namespace ScryfallApi.Client.Models
46
{
@@ -10,23 +12,56 @@ public class CardFace : BaseItem
1012
[JsonProperty("name")]
1113
public string Name { get; set; }
1214

15+
/// <summary>
16+
/// The mana cost for this card. This value will be any empty string "" if the cost is
17+
/// absent. Remember that per the game rules, a missing mana cost and a mana cost of {0}
18+
/// are different values.
19+
/// </summary>
20+
[JsonProperty("mana_cost")]
21+
public string ManaCost { get; set; }
22+
1323
/// <summary>
1424
/// The type line of this particular face.
1525
/// </summary>
1626
[JsonProperty("type_line")]
1727
public string TypeLine { get; set; }
1828

1929
/// <summary>
20-
///
30+
/// The Oracle text for this face, if any.
2131
/// </summary>
22-
[JsonProperty("mana_cost")]
23-
public string ManaCost { get; set; }
24-
25-
2632
[JsonProperty("oracle_text")]
2733
public string OracleText { get; set; }
2834

35+
/// <summary>
36+
/// This face’s colors.
37+
/// </summary>
38+
[JsonProperty("colors")]
39+
public string[] Colors { get; set; }
40+
41+
/// <summary>
42+
/// This card’s power, if any. Note that some cards have powers that are not numeric,
43+
/// such as *.
44+
/// </summary>
45+
[JsonProperty("power")]
46+
public string Power { get; set; }
47+
48+
/// <summary>
49+
/// This card’s toughness, if any. Note that some cards have toughnesses that are not
50+
/// numeric, such as *.
51+
/// </summary>
52+
[JsonProperty("toughness")]
53+
public string Toughness { get; set; }
54+
55+
[JsonProperty("flavor_text")]
56+
public string FlavorText { get; set; }
57+
58+
[JsonProperty("artist")]
59+
public string Artist { get; set; }
60+
2961
[JsonProperty("illustration_id")]
3062
public string IllustrationId { get; set; }
63+
64+
[JsonProperty("image_uris")]
65+
public Dictionary<string, Uri> ImageUris { get; set; }
3166
}
3267
}

src/ScryfallApi.Client/ScryfallApi.Client.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageId>ScryfallAPI.Client</PackageId>
6+
<Version>1.0.0</Version>
7+
<Authors>Gonkers</Authors>
8+
<Company />
9+
<Description>.NET client library for accessing the scryfall.com API</Description>
10+
<PackageProjectUrl>https://github.com/Gonkers/Scryfall-API-Client</PackageProjectUrl>
11+
<RepositoryUrl>https://github.com/Gonkers/Scryfall-API-Client.git</RepositoryUrl>
12+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
13+
<PackageTags>scryfall scryfall-api</PackageTags>
514
</PropertyGroup>
615

716
<ItemGroup>

0 commit comments

Comments
 (0)