Skip to content

Commit 34cfdce

Browse files
committed
Add bulk data API
1 parent b09d433 commit 34cfdce

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using ScryfallApi.Client.Models;
2+
3+
namespace ScryfallApi.Client.Apis;
4+
5+
///<inheritdoc cref="IBulkData"/>
6+
public class BulkData : IBulkData
7+
{
8+
private readonly BaseRestService _restService;
9+
10+
internal BulkData(BaseRestService restService)
11+
{
12+
_restService = restService;
13+
}
14+
15+
public Task<ResultList<BulkDataItem>> Get() => _restService.GetAsync<ResultList<BulkDataItem>>("/bulk-data", false);
16+
17+
public async Task<ICollection<BulkDataItem>> Get(DateTimeOffset updatedSince)
18+
{
19+
var bulkData = await Get();
20+
return bulkData.Data.Where(d => d.LastUpdated >= updatedSince).ToList();
21+
}
22+
23+
public async Task<BulkDataItem> Get(DateTimeOffset updatedSince, string bulkDataType) =>
24+
(await Get(updatedSince)).FirstOrDefault(d => d.Type.Equals(bulkDataType, StringComparison.OrdinalIgnoreCase));
25+
26+
public static class Types
27+
{
28+
/// <summary>
29+
/// A JSON file containing one Scryfall card object for each Oracle ID on Scryfall. The
30+
/// chosen sets for the cards are an attempt to return the most up-to-date recognizable
31+
/// version of the card.
32+
/// </summary>
33+
public static string OracleCards => "oracle_cards";
34+
35+
/// <summary>
36+
/// A JSON file of Scryfall card objects that together contain all unique artworks. The
37+
/// chosen cards promote the best image scans.
38+
/// </summary>
39+
public static string UniqueArtwork => "unique_artwork";
40+
41+
/// <summary>
42+
/// A JSON file containing every card object on Scryfall in English or the printed
43+
/// language if the card is only available in one language.
44+
/// </summary>
45+
public static string DefaultCards => "default_cards";
46+
47+
/// <summary>
48+
/// A JSON file containing every card object on Scryfall in every language.
49+
/// </summary>
50+
public static string AllCards => "all_cards";
51+
52+
/// <summary>
53+
/// A JSON file containing all Rulings on Scryfall. Each ruling refers to cards via an `oracle_id`.
54+
/// </summary>
55+
public static string Rulings => "rulings";
56+
}
57+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using ScryfallApi.Client.Models;
2+
3+
namespace ScryfallApi.Client.Apis;
4+
5+
/// <summary>Bulk Data API</summary>
6+
public interface IBulkData
7+
{
8+
/// <summary>
9+
/// Get information on bulk data collections and download links
10+
/// </summary>
11+
/// <returns></returns>
12+
Task<ResultList<BulkDataItem>> Get();
13+
14+
/// <summary>
15+
/// Return just the items that have been updated since the date and time provided
16+
/// </summary>
17+
/// <param name="updatedSince"></param>
18+
/// <returns></returns>
19+
Task<ICollection<BulkDataItem>> Get(DateTimeOffset updatedSince);
20+
21+
/// <summary>
22+
/// Return just the item type specified that has been updated since the date and time provided
23+
/// </summary>
24+
/// <param name="updatedSince"></param>
25+
/// <param name="bulkDataType"></param>
26+
/// <returns></returns>
27+
Task<BulkDataItem> Get(DateTimeOffset updatedSince, string bulkDataType);
28+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace ScryfallApi.Client.Models;
4+
5+
public class BulkDataItem : BaseItem
6+
{
7+
/// <summary>The Content-Encoding encoding that will be used to transmit this file when you download it.</summary>
8+
[JsonPropertyName("content_encoding")]
9+
public string ContentEncoding { get; set; }
10+
11+
/// <summary>The MIME type of this file.</summary>
12+
[JsonPropertyName("content_type")]
13+
public string ContentType { get; set; }
14+
15+
/// <summary>A human-readable description for this file.</summary>
16+
[JsonPropertyName("description")]
17+
public string Description { get; set; }
18+
19+
/// <summary>The URI that hosts this bulk file for fetching.</summary>
20+
[JsonPropertyName("download_uri")]
21+
public Uri DownloadUri { get; set; }
22+
23+
/// <summary>The size of this file in integer bytes.</summary>
24+
[JsonPropertyName("compressed_size")]
25+
public long FileSizeInBytes { get; set; }
26+
27+
/// <summary>A unique ID for this bulk item.</summary>
28+
[JsonPropertyName("id")]
29+
public Guid Id { get; set; }
30+
31+
/// <summary>The time when this file was last updated.</summary>
32+
[JsonPropertyName("updated_at")]
33+
public DateTimeOffset LastUpdated { get; set; }
34+
35+
/// <summary>A human-readable name for this file.</summary>
36+
[JsonPropertyName("name")]
37+
public string Name { get; set; }
38+
39+
/// <summary>A computer-readable string for the kind of bulk item.</summary>
40+
[JsonPropertyName("type")]
41+
public string Type { get; set; }
42+
43+
/// <summary>The Scryfall API URI for this file.</summary>
44+
[JsonPropertyName("uri")]
45+
public Uri Uri { get; set; }
46+
}

src/ScryfallApi.Client/ScryfallApiClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class ScryfallApiClient : IScryfallApiClient
2222
///<inheritdoc cref="ISymbology"/>
2323
public ISymbology Symbology => _symbology.Value;
2424

25+
private readonly Lazy<IBulkData> _bulkData;
26+
///<inheritdoc cref="IBulkData"/>
27+
public IBulkData BulkData => _bulkData.Value;
28+
29+
2530
/// <summary>
2631
/// Instantiate a new Scryfall API client.
2732
/// </summary>
@@ -41,5 +46,6 @@ public ScryfallApiClient(HttpClient httpClient, ScryfallApiClientConfig clientCo
4146
_catalogs = new Lazy<ICatalogs>(() => new Catalogs(restService));
4247
_sets = new Lazy<ISets>(() => new Sets(restService));
4348
_symbology = new Lazy<ISymbology>(() => new Symbology(restService));
49+
_bulkData = new Lazy<IBulkData>(() => new BulkData(restService));
4450
}
4551
}

0 commit comments

Comments
 (0)