Skip to content

Commit 62122be

Browse files
committed
More updates and examples
1 parent 6572020 commit 62122be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+25300
-9178
lines changed

samples/ScryfallApi.NetFxExample/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ static async Task Main(string[] args)
1515
var client = new ScryfallApiClient(httpClient);
1616
do
1717
{
18-
Console.Clear();
19-
var randomCard = await client.Cards.GetRandom();
20-
Console.WriteLine(DrawCard(randomCard));
18+
try
19+
{
20+
var randomCard = await client.Cards.GetRandom();
21+
Console.Clear();
22+
Console.WriteLine(DrawCard(randomCard));
23+
}
24+
catch (ScryfallApiException ex)
25+
{
26+
Console.Clear();
27+
Console.WriteLine($"Error: {ex.Message}");
28+
Console.WriteLine($"Status Code: {ex.ResponseStatusCode}");
29+
Console.WriteLine($"Remote Call: {ex.RequestMethod} {ex.RequestUri}");
30+
}
2131
Console.WriteLine(Environment.NewLine + "Press any key for a new card. Press Esc to quit.");
2232
} while (Console.ReadKey().Key != ConsoleKey.Escape);
2333
}
@@ -61,7 +71,6 @@ static string DrawCard(Card card)
6171
\---------------------------------/";
6272
}
6373

64-
6574
static List<string> SplitOnWidth(string text, int width)
6675
{
6776
var rawLines = text.Split(new[] { "\n" }, StringSplitOptions.None);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@page
2+
@model ScryfallApi.WebSample.Pages.CardsModel
3+
@{
4+
<form method="get">
5+
<select name="set" asp-items="Model.SetList" onchange="submit()"></select>
6+
</form>
7+
8+
if (Model.CardList is not null)
9+
{
10+
<p>
11+
@foreach (var card in Model.CardList)
12+
{
13+
<a href="@card.ScryfallUri"><img alt="@card.Name" title="@card.Name" src="@card.ImageUris["small"]" /></a>
14+
}
15+
</p>
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 Microsoft.AspNetCore.Mvc.Rendering;
8+
using ScryfallApi.Client;
9+
using ScryfallApi.Client.Models;
10+
11+
namespace ScryfallApi.WebSample.Pages
12+
{
13+
public class CardsModel : PageModel
14+
{
15+
private readonly ScryfallApiClient _scryfallApi;
16+
public List<SelectListItem> SetList { get; set; }
17+
public ICollection<Card> CardList { get; set; }
18+
19+
public CardsModel(ScryfallApiClient scryfallApi)
20+
{
21+
_scryfallApi = scryfallApi ?? throw new ArgumentNullException(nameof(scryfallApi));
22+
}
23+
24+
public async Task<IActionResult> OnGet([FromQuery] string set)
25+
{
26+
var sets = await _scryfallApi.Sets.Get();
27+
SetList = sets.Data.OrderBy(s => s.Name).Select(s => new SelectListItem(s.Name, s.Code)).ToList();
28+
29+
var selectedItem = SetList.FirstOrDefault(li => li.Value.Equals(set));
30+
if (selectedItem is not null)
31+
{
32+
selectedItem.Selected = true;
33+
CardList = (await _scryfallApi.Cards.Search($"e:{selectedItem.Value}", 1, SearchOptions.CardSort.Name)).Data;
34+
}
35+
else
36+
CardList = new List<Card>();
37+
38+
return Page();
39+
}
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page
2+
@model ScryfallApi.WebSample.Pages.SetsModel
3+
@{
4+
5+
<ul>
6+
@foreach (var block in Model.MtgExpansions.GroupBy(s => s.Block).OrderByDescending(b => b.Min(s => s.ReleaseDate)))
7+
{
8+
<li>@block.Key
9+
<ul>
10+
@foreach (var set in block.OrderByDescending(s => s.ReleaseDate))
11+
{
12+
<li>@set.Name (@set.Code) - @set.ReleaseDate.Value.ToShortDateString()</li>
13+
}
14+
</ul>
15+
</li>
16+
}
17+
</ul>
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Mvc.RazorPages;
2+
using ScryfallApi.Client;
3+
using ScryfallApi.Client.Models;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace ScryfallApi.WebSample.Pages
10+
{
11+
public class SetsModel : PageModel
12+
{
13+
private readonly ScryfallApiClient _scryfallApi;
14+
public List<Set> MtgExpansions { get; set; }
15+
16+
public SetsModel(ScryfallApiClient scryfallApi)
17+
{
18+
_scryfallApi = scryfallApi ?? throw new ArgumentNullException(nameof(scryfallApi));
19+
}
20+
21+
public async Task OnGet()
22+
{
23+
var setsResult = await _scryfallApi.Sets.Get();
24+
MtgExpansions = new List<Set>(setsResult.Data.
25+
Where(s => s.SetType.Equals("expansion") && !s.IsDigital));
26+
}
27+
}
28+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<li class="nav-item">
2222
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
2323
</li>
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-page="/Sets">Sets</a>
26+
</li>
27+
<li class="nav-item">
28+
<a class="nav-link text-dark" asp-area="" asp-page="/Cards">Cards</a>
29+
</li>
2430
<li class="nav-item">
2531
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
2632
</li>

samples/ScryfallApi.WebSample/Startup.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,25 @@ public void ConfigureServices(IServiceCollection services)
2222
{
2323
services.AddRazorPages();
2424
services.AddLogging();
25-
services.AddScryfallApiClient(config => { config.CacheDuration = TimeSpan.FromHours(1); });
25+
26+
27+
// Example of pulling the config from IConfiguration
28+
/*
29+
var scryfallApiClientConfig = Configuration.GetSection("ScryfallApiClient").Get<ScryfallApiClientConfig>();
30+
services.AddScryfallApiClient(scryfallApiClientConfig);
31+
*/
32+
33+
// Example of using default settings
34+
/*
35+
services.AddScryfallApiClient();
36+
*/
37+
38+
// Example of customizing settings with code
39+
services.AddScryfallApiClient(config =>
40+
{
41+
config.CacheDuration = TimeSpan.FromMinutes(30);
42+
config.UseSlidingCacheExpiration = true;
43+
});
2644
}
2745

2846
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

samples/ScryfallApi.WebSample/appsettings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
"Default": "Warning"
55
}
66
},
7-
"AllowedHosts": "*"
7+
"AllowedHosts": "*",
8+
"ScryfallApiClient": {
9+
"ScryfallApiBaseAddress": "https://api.scryfall.com/",
10+
"EnableCaching": true,
11+
"CacheDuration": "01:00:00",
12+
"UseSlidingCacheExpiration": false
13+
}
814
}
Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
1-
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
22
for details on configuring this project to bundle and minify static web assets. */
3-
body {
4-
padding-top: 50px;
5-
padding-bottom: 20px;
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
/* Provide sufficient contrast against white background */
11+
a {
12+
color: #0366d6;
13+
}
14+
15+
.btn-primary {
16+
color: #fff;
17+
background-color: #1b6ec2;
18+
border-color: #1861ac;
19+
}
20+
21+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22+
color: #fff;
23+
background-color: #1b6ec2;
24+
border-color: #1861ac;
625
}
726

8-
/* Wrapping element */
9-
/* Set some basic padding to keep content from hitting the edges */
10-
.body-content {
11-
padding-left: 15px;
12-
padding-right: 15px;
27+
/* Sticky footer styles
28+
-------------------------------------------------- */
29+
html {
30+
font-size: 14px;
31+
}
32+
@media (min-width: 768px) {
33+
html {
34+
font-size: 16px;
35+
}
1336
}
1437

15-
/* Carousel */
16-
.carousel-caption p {
17-
font-size: 20px;
18-
line-height: 1.4;
38+
.border-top {
39+
border-top: 1px solid #e5e5e5;
40+
}
41+
.border-bottom {
42+
border-bottom: 1px solid #e5e5e5;
1943
}
2044

21-
/* Make .svg files in the carousel display properly in older browsers */
22-
.carousel-inner .item img[src$=".svg"] {
23-
width: 100%;
45+
.box-shadow {
46+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
2447
}
2548

26-
/* QR code generator */
27-
#qrCode {
28-
margin: 15px;
49+
button.accept-policy {
50+
font-size: 1rem;
51+
line-height: inherit;
2952
}
3053

31-
/* Hide/rearrange for smaller screens */
32-
@media screen and (max-width: 767px) {
33-
/* Hide captions */
34-
.carousel-caption {
35-
display: none;
36-
}
54+
/* Sticky footer styles
55+
-------------------------------------------------- */
56+
html {
57+
position: relative;
58+
min-height: 100%;
59+
}
60+
61+
body {
62+
/* Margin bottom by footer height */
63+
margin-bottom: 60px;
64+
}
65+
.footer {
66+
position: absolute;
67+
bottom: 0;
68+
width: 100%;
69+
white-space: nowrap;
70+
line-height: 60px; /* Vertically center the text there */
3771
}

samples/ScryfallApi.WebSample/wwwroot/css/site.min.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)