Skip to content

Commit 35a9afd

Browse files
committed
Fix card search sort, remove unused model code, fix card face model, update search example to include transform images
1 parent ecea2bc commit 35a9afd

File tree

5 files changed

+57
-127
lines changed

5 files changed

+57
-127
lines changed

samples/ScryfallApi.WebSample/Pages/Search.cshtml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@
2424
<h3>Result: <a href="@card.ScryfallUri">@card.Name</a></h3>
2525
<div class="row">
2626
<div class="col-md-12">
27-
<a href="@card.ScryfallUri">
28-
<img src="@card.ImageUris["normal"]" style="max-width: 320px;" />
29-
</a>
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>
3040
</div>
3141
</div>
3242
}
33-
}
34-
43+
}

samples/ScryfallApi.WebSample/Pages/Search.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void OnGet()
3030

3131
public async Task<ActionResult> OnPostAsync()
3232
{
33-
Results = await _scryfallApi.Cards.Search(Query, 1, CardSort.Name);
33+
Results = await _scryfallApi.Cards.Search(Query, 1, CardSort.Cmc );
3434

3535
return Page();
3636
}

src/ScryfallApi.Client/Apis/Cards.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +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-
public async Task<ResultList<Card>> Search(string query, int page, CardSort sort) => await GetAsync<ResultList<Card>>($"/cards/search?q={query}&page={page}&sort={sort}");
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()}");
1819
}
1920
}

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
}

0 commit comments

Comments
 (0)